file upload has image but if i browse new iamge its stills showing old images,in the same folder
below is the code:
Protected Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Update.Click
Dim id As Integer = Request.QueryString("Id")
Dim ResourcesTitle, ResourcesDimension, ImageName, ZoomImageName, Color As String
Color = HiddenField_ColorValues.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\"
PathImg = imgfolder & ImageName
PathImgZ = imgfolder & ZoomImageName
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)
End If
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
plz help me with the code
i dont knw whats the error
no its not overriding the previous image for me, as saving location is same but the but uploaded image is of diffrent name but at the time of saving it has the same name as that of previous one
Smadhu
Member
511 Points
999 Posts
fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:11 AM|LINK
fileupload control,overwrites the files uploaded previously or not??
me_ritz
Star
9339 Points
1448 Posts
Re: fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:14 AM|LINK
Yes...it overwrites the previously upload file..if the new one is of the same name and at the same location.
srinanthuram
Contributor
6800 Points
1549 Posts
Re: fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:14 AM|LINK
hi
pls ref this url
http://www.codeproject.com/Articles/20023/ASP-NET-2-0-FileUpload-Server-Control
thank u
vivekreddy
Member
200 Points
96 Posts
Re: fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:17 AM|LINK
Hi,
yes, it does.
Smadhu
Member
511 Points
999 Posts
Re: fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:31 AM|LINK
but for me its not overwriting
file upload has image but if i browse new iamge its stills showing old images,in the same folder
below is the code:
Protected Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Update.Click Dim id As Integer = Request.QueryString("Id") Dim ResourcesTitle, ResourcesDimension, ImageName, ZoomImageName, Color As String Color = HiddenField_ColorValues.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\" PathImg = imgfolder & ImageName PathImgZ = imgfolder & ZoomImageName 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) End If 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 plz help me with the code i dont knw whats the errorSmadhu
Member
511 Points
999 Posts
Re: fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:32 AM|LINK
no its not overriding the previous image for me, as saving location is same but the but uploaded image is of diffrent name but at the time of saving it has the same name as that of previous one
plz check my code n tell me where is the error
thnx
basheerkal
Star
10672 Points
2426 Posts
Re: fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:35 AM|LINK
If You use SaveAs method unconditionally it will overwrite. If needed you can avoid it as show in the msdn page
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.saveas.aspx
B
(Talk less..Work more)
vjp.vjp
Member
93 Points
89 Posts
Re: fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:39 AM|LINK
yap
Smadhu
Member
511 Points
999 Posts
Re: fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:40 AM|LINK
i m already using saveas
as u can see in my code
Smadhu
Member
511 Points
999 Posts
Re: fileupload control,overwrites the files uploaded previously or not??
Feb 21, 2012 11:44 AM|LINK
can u plz check my code..............i m really confused y its not able to override the files
thnx