Click here to Skip to main content
15,891,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi m getting error while uploading file to target folder in asp.net.. here is my code..

C#
public string uploadFile(string fileName, string folderName)
  {

      if (fileName == "")
      {

          return "Invalid filename supplied";

      }

      if (fileUpload.PostedFile.ContentLength == 0)
      {

          return "Invalid file content";

      }

      fileName = System.IO.Path.GetFileName(fileName);

      if (folderName == "")
      {

          return "Path not found";

      }

      try
      {

          if (fileUpload.PostedFile.ContentLength <= 2048000)
          {

              fileUpload.PostedFile.SaveAs(Server.MapPath(folderName) + "\\" + fileName);

              return "File uploaded successfully";

          }

          else
          {

              return "Unable to upload,file exceeds maximum limit";

          }

      }

      catch (UnauthorizedAccessException ex)
      {

          return ex.Message + "Permission to upload file denied";

      }

  }



and here is my btnSave code.

C#
protected void btnSave_Click(object sender, EventArgs e)
    {
        string strFilename, strMessage;

        strFilename = fileUpload.PostedFile.FileName.ToString();

        strMessage = uploadFile(strFilename, ConfigurationSettings.AppSettings["folderPath"]);

        lblMessage.Text = strMessage;

        //lblMessage.ForeColor = Color.Red;
    }



error is
fileUpload.PostedFile.SaveAs(Server.MapPath(folderName) + "\\" + fileName);


Could not find a part of the path 'C:\Users\admin\Documents\Visual Studio 2008\WebSites\pmsw(new)\Admin\10.3.2\Concrete_Basement_Wall.xls'. 


and i created one folder as 10.3.2.so i want to upload that file into this folder..can any one solve??
Posted

1 solution

Hi,

Whats value you have for folder name parameter. It must be relative path value....

Check here[^] and here[^].
 
Share this answer
 
Comments
ythisbug 28-Feb-12 3:52am    
thank you.
Tech Code Freak 28-Feb-12 5:29am    
5up!

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