I have a form which I use for uploading pics using the AsyncFileUpload that works as expected. After the AsyncFileUpload.SaveAs ends I am trying to resize the uploaded pic with the following code -
ProtectedSub FileUploadComplete(ByVal sender AsObject, ByVal e AsEventArgs)
Dim filename AsString = System.IO.Path.GetFileName(AsyncFileUpload1.FileName)
AsyncFileUpload1.SaveAs(Server.MapPath(UploadFolderPath) + filename)
Dim originalBM AsNewBitmap(Server.MapPath(UploadFolderPath) + filename)
Dim newheight AsInteger = 300 * originalBM.Height / originalBM.Width
Dim newSize AsNewSize(300, newheight)
Dim newBM AsNewBitmap(originalBM, newSize) ' Dim newFileName AsString = Server.MapPath(UploadFolderPath) + "new." + filename
newBM.Save(newFileName, originalBM.RawFormat)
replaceFiles(Server.MapPath(UploadFolderPath) + filename, newFileName)
EndSub'PrivateFunction replaceFiles(org AsString, newImg AsString) AsBooleanIfFile.Exists(org) AndFile.Exists(newImg) ThenDim fi AsNewFileInfo(org)
Try
fi.Replace(newImg, newImg + ".bak")
ReturnTrueCatch ex AsException
Response.Write(ex.Message)
ReturnFalseEndTryElseReturnFalseEndIfEndFunction
When the code runs I get the following error -
The process cannot access the file because it is being used by another process.
Member
105 Points
627 Posts
Pic resize
Nov 21, 2011 08:30 AM|shtrudel|LINK
Hi there,
I have a form which I use for uploading pics using the AsyncFileUpload that works as expected. After the AsyncFileUpload.SaveAs ends I am trying to resize the uploaded pic with the following code -
When the code runs I get the following error -
The process cannot access the file because it is being used by another process.
How can I avoid this error ?
Member
690 Points
150 Posts
Re: Pic resize
Nov 21, 2011 09:08 AM|maroasp.net|LINK
Hi,
you need to disppose the bitmap object to realese all its reasources aftre saving it.
newBM.Dispose();