Click here to Skip to main content
15,916,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a upload function in my system which allow user to upload their pdf file.

when i upload file from my pc to server , no issue

my pc --> //192.168.2.5/web/file/ <---- my system source code server

after i change the upload destination to other server( //192.10.1.1/Intranet/ ),it fail to upload.

firewall has been open between server 192.168.2.5 and 192.10.1.1

below are my upload function

C#
protected void btn_add(object sender, EventArgs e)
 {
     string title = title_p.Text;
     int loggedUserID = Convert.ToInt32(Session["loggedUserID"]);
     List<BOL.UserInfo> userslist = new UserInfos().List();
     BOL.UserInfo loggeduser = userslist.Where(x => x.UserID == loggedUserID).FirstOrDefault();
     if (FileUploadControl.HasFile)
     {

         String ext = System.IO.Path.GetExtension(FileUploadControl.FileName);
         if (ext.ToLower() == ".pdf" )
         {
             string path1 = "\\\\192.168.1.10\\Intranet\\";
             if (FileUploadControl.HasFile)
             {

                 int fileSize = FileUploadControl.PostedFile.ContentLength;
                 //int maxFileSize = 1024;
                 if (FileUploadControl.PostedFile.ContentLength > 5242880)
                 {
                     ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + "File size too big" + "');", true);
                     return;
                 }
                 else
                 {

                     string filename = Path.GetFileName(FileUploadControl.FileName);
                     try
                     {
                         if (System.IO.File.Exists(Server.MapPath(path1) + filename))
                         {
                             filename = (Path.GetFileNameWithoutExtension(FileUploadControl.FileName) + DateTime.Now.ToString("yyyy-MM-dd HHmmtt") + Path.GetExtension(FileUploadControl.FileName));
                             FileUploadControl.SaveAs(Server.MapPath(path1) + filename);

                             DAL.leadp insertdata = new leadp();
                             //training_insert.add_request(loggeduser.SUBSIDIARY_CD, Main_CD, SUB_CD, Justification, loggeduser.EmployeeNo, loggeduser.CostCenter, exp_datee.ToString(), e_name, loca, filename, path1+filename);
                             insertdata.lead_insert(loggeduser.SUBSIDIARY_CD, title,loggeduser.EmployeeNo, filename, path1 + filename);
                             string message = "Submitted";
                             ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
                             //Response.Redirect("erequest_list.aspx");
                         }
                         else
                         {
                             filename = Path.GetFileName(FileUploadControl.FileName);
                             FileUploadControl.SaveAs(Server.MapPath(path1) + filename);

                             DAL.leadp insertdata = new leadp();
                             insertdata.lead_insert(loggeduser.SUBSIDIARY_CD, title, loggeduser.EmployeeNo, filename, path1 + filename);
                             string message = "Submitted";
                             ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
                         }
                     }
                     catch (Exception ex)
                     {
                         //StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                     }
                 }
             }
         }

         else
         {

             ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + "Only can upload pdf file" + "');", true);
         }
     }
     else
     {
         ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + "Please insert pdf file" + "');", true);


     }

 }


What I have tried:

asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Posted
Updated 4-Aug-16 6:22am
Comments
Suvendu Shekhar Giri 3-Aug-16 5:21am    
:O what does that mean, the content of "What I have tried" section?
ZurdoDev 3-Aug-16 10:18am    
I'll bet you the error tells you exactly why it failed. And I'll secondly bet you that it is a permissions issue.

1 solution

Your previous location will work because the uploaded image files are stored within your website root folder which has proper permissions configured in IIS.

Your new path for upload is hosted outside of your website which why you are getting error (e.g permissions error). To overcome that, you would need to setup a virtual directory (with the real directory where you want it) and in IIS ensure that there is no direct access to that folder (paying particular attention to read and directory listing permissions).

PS: As a general rule, work on the principle that what belongs to the website should stay within the wwwroot folder structure, just as (for example) what belongs in "C:\Windows\System32" shouldn't go in "My Documents".
 
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