本文介绍了在服务器上保存文件时出错.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在服务器上上传文件时遇到错误,但是在我的本地主机上工作正常.

我的服务器上载文件的地址是:http://www.tnp.somee.com/Uploads

我使用了以下代码:

I am facing the Error while Uploading the files on the Server, however it is working fine on my localhost.

My Server address where to upload the files are: http://www.tnp.somee.com/Uploads

I used the following Code:

protected void Button1_Click(object sender, EventArgs e)
   {
       string filepath = "www.tnp.somee.com/Uploads";
       HttpFileCollection uploadedFiles = Request.Files;

       for (int i = 0; i < uploadedFiles.Count; i++)

       {

           HttpPostedFile userPostedFile = uploadedFiles[i];



           try

           {

               if (userPostedFile.ContentLength > 0)
               {
                   Label1.Text += "<u>File #" + (i + 1) +
                      "</u><br>";
                   Label1.Text += "File Content Type: " +
                      userPostedFile.ContentType + "<br>";
                   Label1.Text += "File Size: " +
                      userPostedFile.ContentLength + "kb<br>";
                   Label1.Text += "File Name: " +
                      userPostedFile.FileName + "<br>";

                   userPostedFile.SaveAs(filepath + "\\" +
                      System.IO.Path.GetFileName(userPostedFile.FileName));

                   Label1.Text += "Location where saved: " +
                      filepath + "\\" +
                      System.IO.Path.GetFileName(userPostedFile.FileName) +
                      "<p>";
               }
           }
           catch (Exception Ex)
           {
               Label1.Text += "Error: <br>" + Ex.Message;
           }
       }

   }




错误:




Error:

The SaveAs method is configured to require a rooted path, and the path 'www.tnp.somee.com/Uploads\Document.docx' is not rooted.




请尽快帮助我.




Please help me out as soon as Possible.

推荐答案



这篇关于在服务器上保存文件时出错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:42