Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
this my my file uploading code
-------------------------------

C#
protected void Upload_MainImage(object sender, EventArgs e)
      {
          if (BrandUploadImg.HasFile)
          {
              //ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('File Detected');", true);
              BrandUploadImg.SaveAs(MapPath("/PRODIMAGES/" + BrandUploadImg.FileName));
              System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("/PRODIMAGES/") + BrandUploadImg.FileName);
              NormalImage.ImageUrl = "/PRODIMAGES/" + BrandUploadImg.FileName;
              
          }
          UpdatePanel7.Update();
         
      }

This for inserting imagefile into database
=============================================
C#
if (NormalImage.ImageUrl != "")
                        {
                            string imagename = Path.GetFileName(BrandUploadImg.FileName);

                            string filename = Path.GetFileName(BrandUploadImg.FileName);
                            //Server.MapPath("MyVirtualDirectory")
                            string srvpat = Server.MapPath("/PRODIMAGES/") + filename;
                            if (!File.Exists(Server.MapPath("/PRODIMAGES/") + filename))
                                BrandUploadImg.SaveAs(Server.MapPath("/PRODIMAGES/") + filename);
                            string uploadfilename = NormalImage.ImageUrl;



--------------------------------------------------------------
But it shows the errors like
1.Could not find a file path like D:\folder\...
2.The process cannot access the file 'D:\..... because it is being used by another process.



how to solve these problems,anybody help me please.
Thanks in advance
Posted
Updated 31-Aug-12 18:50pm
v2
Comments
Sandeep Mewara 1-Sep-12 1:15am    
Does this path exists on server: D:\folder\ ?

first of you you have to check where you are trying this application..
in your local pc or in server?

if in local pc then you need to check whether the application is in c or not because for some security reason win7 does not allow to access completely c drive or windows drive; so change application path to another drive.
If it is in server you have to check that file access permission are granted or not if not ask your administrator to give access to the image folder path.

Your code seems good...no problem over there..chek what i mentioned...
If still problem please share without hesitating.
 
Share this answer
 
Hello,

I couldn't see any data base related things in your code snippet. I hope you are trying to upload image to the server, Then you should ensure D drive PRODIMAGES folder has write permission...


Thanks!!!
 
Share this answer
 
v2
Hi,
Thanks for your quick replay.
I solved this problem by removing the below three lines from code and also place BrandUploadImg.Dispose() method after uploading the image.

===========================================================================
BrandUploadImg.SaveAs(MapPath("/PRODIMAGES/" + BrandUploadImg.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("/PRODIMAGES/") + BrandUploadImg.FileName);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900