"Göran Andersson" <> wrote in message
news:%...
> tshad wrote:
>> oThumbnail.Save is giving me an error:
>>
>> System.Runtime.InteropServices.ExternalException: A generic error
>> occurred in GDI+.
>>
>> theFileName = New FileInfo(strFileName)
>> fileOut = fileIn.Substring(0,fileIn.LastIndexOf(".")) &
>> session("User").CompanyID & fileIn.Substring(fileIn.LastIndexOf("."))
>> pathFileOut = Server.MapPath("\Uploads") & "\" &
>> fileIn.Substring(0,fileIn.LastIndexOf(".")) & "Temp" &
>> fileIn.Substring(fileIn.LastIndexOf("."))
>> MyFile2.PostedFile.SaveAs(PathFileOut)
>>
>> ' Write out a temporary file that will be read back in for thumbnail
>> Dim oImage As System.Drawing.Image
>> oImage = oImage.FromFile(pathFileOut)
>>
>> ' Read back in File, create thumbnail and save it
>> Dim oThumbnail as System.Drawing.Image
>> oThumbnail = oImage.GetThumbnailImage(100,200,Nothing,Nothing)
>> thumbnailFileOut = Server.MapPath("\Uploads") & "\" &
>> fileIn.Substring(0,fileIn.LastIndexOf(".")) &
>> fileIn.Substring(fileIn.LastIndexOf("."))
>> oThumbnail.Save(Server.MapPath("uploads") & "\" & fileOut,
>> ImageFormat.Jpeg)
>>
>> I am getting the error on the last line.
>>
>> The path and filename are valid - what causes the problem here?
>>
>> Thanks,
>>
>> Tom
>
> You create the string thumbnailFileOut on the line before, but then you
> use the string fileOut instead.
Your right. I missed that. That was a carryover from my testing.
I also tried to make some changes such as not creating 2 image files and
working only with one (oImage).
I found that my ...Temp4... file is being locked and I can't get rid of it.
I thought that the oImage=nothing would release it. It seems to if I am
using 2 Image objects as I was doing before.
theFileName = New FileInfo(strFileName)
fileOut = fileIn.Substring(0,fileIn.LastIndexOf(".")) &
session("User").CompanyID & fileIn.Substring(fileIn.LastIndexOf("."))
pathFileOut = Server.MapPath("\Uploads") & "\" &
fileIn.Substring(0,fileIn.LastIndexOf(".")) & "Temp4" &
fileIn.Substring(fileIn.LastIndexOf("."))
MyFile2.PostedFile.SaveAs(PathFileOut)
CompanyPicture.Text = fileout
Dim oImage As System.Drawing.Image
oImage = oImage.FromFile(pathFileOut)
oImage = oImage.GetThumbnailImage(100,200,Nothing,Nothing)
FileOut = Server.MapPath("/Uploads") & "/" &
fileIn.Substring(0,fileIn.LastIndexOf(".")) &
fileIn.Substring(fileIn.LastIndexOf("."))
oImage.Save(FileOut, ImageFormat.Jpeg)
oImage = nothing
Also, is there a better way to handle this so I don't have to create the
temporary file that I am uploading (MyFile2.PostedFile.SaveAs(PathFileOut)).
I am doing this so I can use the FromFile method to get the image into the
image object. If I could get it directly into the image object I wouldn't
have the problem with the temporary file locking. Once it locks I can't
seem to get it unlocked (which is why I am now at Temp4 - I now have
Temp-Temp4 locked). I can't delete it even if I stop the web server.
>
> Another thing; Server.MapPath("\Uploads") should be
> Server.MapPath("/Uploads"). A virtual path uses /, never \.
I did try it with both "/Uploads" and "\Uploads" and it seems to work in
both cases.
Thanks,
Tom
>
> --
> Göran Andersson
> _____
> http://www.guffa.com