Click here to Skip to main content
15,886,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to store resume into folder which is in my project.following code only store path into db.following code only store path in db but not store in folder help me?


C#
string img_code = rd.RandomString(30);

 string ext = System.IO.Path.GetExtension(FileUpload1.FileName);


 filePath = Server.MapPath("~/Docs/" + Session["uid"].ToString() + "-" + img_code + ext);
 FileUpload1.SaveAs(filePath);
 imagepath = "Docs/" + Session["uid"].ToString() + "-" + img_code + ext;
 HiddenField1.Value = "Docs/" + Session["uid"].ToString() + "-" + img_code + ext;

 if (FileUpload1.PostedFile != null)
{
     // Check file size (mustn't be 0)
     HttpPostedFile myFile = FileUpload1.PostedFile;
     int nFileLen = myFile.ContentLength;
     if (nFileLen > 0)
     {
         // Read file into a data stream
         byte[] myData = new Byte[nFileLen];
         myFile.InputStream.Read(myData, 0, nFileLen);
         myFile.InputStream.Dispose();

         // Save the stream to disk as temporary file.
         // make sure the path is unique!
         System.IO.FileStream newFile
                 = new System.IO.FileStream(filePath, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
         newFile.Write(myData, 0, myData.Length);


         newFile.Close();


     }
 }

 Label10.Text = "Uploaded successfully";
Posted

1 solution

C#
FileUpload1.SaveAs(filePath);


I'd expect this to have saved your file, without all the other stuff you're doing. I see no DB code here at all, just two attempts to save the file. Where does this save to the DB ? What do you end up with on your file system ? I wonder if your second block is breaking the fact that the first line had saved the file for you ? Have you debugged this at all ?
 
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