with file upload i m uploading file in folder path:images/resources with the id name such as:1009.png
but if i am again edit that page and browser another image so old image should replace by new image having same id
but i m not able to do that,Below is the code i m using
help me to solve the prblem
asp code:
<asp:Label ID="lblResourcesImg" class="lbl" runat="server" Text="Upload Image"></asp:Label>
<asp:FileUpload ID="ImgUpload" runat="server" CssClass="Upload" EnableViewState="true" />
<asp:Label ID="ImgError" runat="server" Text="The Image must be png with 120X73px in dimension."></asp:Label>
vb.net code:
Protected Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Update.Click
Dim id As Integer
Dim ResourcesTitle, ResourcesDimension, ImageName, ZoomImageName, Color As String
Color = HiddenField_ColorValues.Value
id = ResourcesId.Value
ResourcesTitle = txbResourcesTitle.Text.Trim
ResourcesDimension = txbResourcesDimension.Text.Trim
Dim fileuploadName = ImgUpload.FileName
Dim ImgNameWithoutExtension As String = id
Dim ImgExtension = Path.GetExtension(fileuploadName)
Dim ZoomfileuploadName = ZoomUpload.FileName
Dim ZoomImgNameWithoutExtension As String = "Z-" & id
Dim ZoomImgExtension = Path.GetExtension(ZoomfileuploadName)
If ImgUpload.HasFile And ZoomUpload.HasFile Then
ImageName = ImgNameWithoutExtension & ImgExtension
Dim UploadedImageType As String = ImgUpload.PostedFile.ContentType.ToString().ToLower()
Dim UploadedImageFileName As String = ImgUpload.PostedFile.FileName
Dim UploadedImage As System.Drawing.Image = System.Drawing.Image.FromStream(ImgUpload.PostedFile.InputStream)
Dim UploadedImageWidth As Single = UploadedImage.PhysicalDimension.Width
Dim UploadedImageHeight As Single = UploadedImage.PhysicalDimension.Height
Dim ZoomUploadedImageType As String = ZoomUpload.PostedFile.ContentType.ToString().ToLower()
Dim ZoomUploadedImageFileName As String = ZoomUpload.PostedFile.FileName
Dim ZoomUploadedImage As System.Drawing.Image = System.Drawing.Image.FromStream(ZoomUpload.PostedFile.InputStream)
Dim ZoomUploadedImageWidth As Single = ZoomUploadedImage.PhysicalDimension.Width
Dim ZoomUploadedImageHeight As Single = ZoomUploadedImage.PhysicalDimension.Height
ZoomImageName = ZoomImgNameWithoutExtension & ZoomImgExtension
If UploadedImageWidth <> 100 Or UploadedImageHeight <> 130 Then
ImgError.ControlStyle.ForeColor = Drawing.Color.Red
ImgError.Text = "The image uploaded must be 120px X 73px in dimension."
ElseIf ZoomUploadedImageWidth <> 1028 Or ZoomUploadedImageHeight <> 631 Then
ZoomImgError.ControlStyle.ForeColor = Drawing.Color.Red
ZoomImgError.Text = "The image uploaded must be 1028px X 631px in dimension."
Else
Dim strFilePath, PathImg, PathImgZ As String
Dim imgfolder As String = "~\Images\Resources\"
strFilePath = Server.MapPath(imgfolder) & ImageName
ImgUpload.PostedFile.SaveAs(strFilePath)
strFilePath = Server.MapPath(imgfolder) & ZoomImageName
ZoomUpload.PostedFile.SaveAs(strFilePath)
'Dim success As Integer = ResourcesHelper.UpdateResources(id, ResourcesTitle, ResourcesDimension, ImageName, ZoomImageName, Color)
'If success Then
' ErrorDisplay.Text = "Updated Successfully"
' MultiView1.SetActiveView(View2)
'End If
End If
Else
End If
Dim success As Integer = ResourcesHelper.UpdateResources(id, ResourcesTitle, ResourcesDimension, Color)
If success Then
ErrorDisplay.Text = "Updated Successfully"
MultiView1.SetActiveView(View2)
End If
End Sub
Smadhu
Member
509 Points
980 Posts
fileupload not replacing previouslly added image
Feb 21, 2012 09:49 AM|LINK
with file upload i m uploading file in folder path:images/resources with the id name such as:1009.png but if i am again edit that page and browser another image so old image should replace by new image having same id but i m not able to do that,Below is the code i m using help me to solve the prblem asp code: <asp:Label ID="lblResourcesImg" class="lbl" runat="server" Text="Upload Image"></asp:Label> <asp:FileUpload ID="ImgUpload" runat="server" CssClass="Upload" EnableViewState="true" /> <asp:Label ID="ImgError" runat="server" Text="The Image must be png with 120X73px in dimension."></asp:Label> vb.net code: Protected Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Update.Click Dim id As Integer Dim ResourcesTitle, ResourcesDimension, ImageName, ZoomImageName, Color As String Color = HiddenField_ColorValues.Value id = ResourcesId.Value ResourcesTitle = txbResourcesTitle.Text.Trim ResourcesDimension = txbResourcesDimension.Text.Trim Dim fileuploadName = ImgUpload.FileName Dim ImgNameWithoutExtension As String = id Dim ImgExtension = Path.GetExtension(fileuploadName) Dim ZoomfileuploadName = ZoomUpload.FileName Dim ZoomImgNameWithoutExtension As String = "Z-" & id Dim ZoomImgExtension = Path.GetExtension(ZoomfileuploadName) If ImgUpload.HasFile And ZoomUpload.HasFile Then ImageName = ImgNameWithoutExtension & ImgExtension Dim UploadedImageType As String = ImgUpload.PostedFile.ContentType.ToString().ToLower() Dim UploadedImageFileName As String = ImgUpload.PostedFile.FileName Dim UploadedImage As System.Drawing.Image = System.Drawing.Image.FromStream(ImgUpload.PostedFile.InputStream) Dim UploadedImageWidth As Single = UploadedImage.PhysicalDimension.Width Dim UploadedImageHeight As Single = UploadedImage.PhysicalDimension.Height Dim ZoomUploadedImageType As String = ZoomUpload.PostedFile.ContentType.ToString().ToLower() Dim ZoomUploadedImageFileName As String = ZoomUpload.PostedFile.FileName Dim ZoomUploadedImage As System.Drawing.Image = System.Drawing.Image.FromStream(ZoomUpload.PostedFile.InputStream) Dim ZoomUploadedImageWidth As Single = ZoomUploadedImage.PhysicalDimension.Width Dim ZoomUploadedImageHeight As Single = ZoomUploadedImage.PhysicalDimension.Height ZoomImageName = ZoomImgNameWithoutExtension & ZoomImgExtension If UploadedImageWidth <> 100 Or UploadedImageHeight <> 130 Then ImgError.ControlStyle.ForeColor = Drawing.Color.Red ImgError.Text = "The image uploaded must be 120px X 73px in dimension." ElseIf ZoomUploadedImageWidth <> 1028 Or ZoomUploadedImageHeight <> 631 Then ZoomImgError.ControlStyle.ForeColor = Drawing.Color.Red ZoomImgError.Text = "The image uploaded must be 1028px X 631px in dimension." Else Dim strFilePath, PathImg, PathImgZ As String Dim imgfolder As String = "~\Images\Resources\" strFilePath = Server.MapPath(imgfolder) & ImageName ImgUpload.PostedFile.SaveAs(strFilePath) strFilePath = Server.MapPath(imgfolder) & ZoomImageName ZoomUpload.PostedFile.SaveAs(strFilePath) 'Dim success As Integer = ResourcesHelper.UpdateResources(id, ResourcesTitle, ResourcesDimension, ImageName, ZoomImageName, Color) 'If success Then ' ErrorDisplay.Text = "Updated Successfully" ' MultiView1.SetActiveView(View2) 'End If End If Else End If Dim success As Integer = ResourcesHelper.UpdateResources(id, ResourcesTitle, ResourcesDimension, Color) If success Then ErrorDisplay.Text = "Updated Successfully" MultiView1.SetActiveView(View2) End If End Subkushpaw
Member
512 Points
123 Posts
Re: fileupload not replacing previouslly added image
Feb 21, 2012 03:09 PM|LINK
See previous post for this issue. I replied today. Basically you have id as integer being assigned a string value, type mismatch is the problem.