在服务器上保存文件时出错. [英] Error while Saving the files on the Server.

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

问题描述

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

我的服务器上载文件的地址是: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.

推荐答案

我想权限问题...

修复链接

SaveAs方法配置为需要root用户路径,并且路径"fp"没有root用户 [ SaveAs将方法配置为需要有根的路径,并且路径< blah>不是植根 [文件上传控制 [
I guess permission issue...

Fix links

The SaveAs method is configured to require a rooted path, and the path ''fp'' is not rooted[^]
The SaveAs method is configured to require a rooted path, and the path <blah> is not rooted[^]
File Upload Control[^]


AFAIK,您不能使用 SaveAs 方法来直接写入FTP服务器.仅支持本地路径和UNC路径.

要将其保存到FTP,您必须使用 FtpWebRequest类.

请参考
[
AFAIK, You cannot use the SaveAs method to write directly to an FTP server. Only local paths and UNC paths are supported.

To save it to FTP you have to use FtpWebRequest class.

Refer This[^] to get an idea.

hope it helps :)


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆