且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

文件上传路径问题

更新时间:2023-11-29 19:47:46

这是怎么回事?我从未见过上载的路径缺少斜线,您必须对此进行一些操作.
How is this happening ? I''ve never seen an uploaded path to be missing slashes, you must be doing something to it.


您好,

我要先将上传的文件复制到服务器中
上传位置.
假设在您的应用程序根程序集中有一个子目录
\ UploadFiles.

示例代码:
Hi,

I thing you should first copy the file you upload into server
upload location.
Let say that in your application root assembly you have a sub directory
\UploadFiles.

Example code:
protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.FileUpload1.HasFile)
        {
            this.FileUpload1.SaveAs(Server.MapPath("~/UploadFiles/" +
                this.FileUpload1.FileName.ToString()));
            string uploadedFile = (Server.MapPath("~/UploadFiles/" +
                this.FileUpload1.FileName.ToString()));
        }
    }




然后,您上传的文件将被复制到您的
\ UploadFiles目录.

请参见上面示例中 uploadedFile 变量的值:




Then the file you''ve uploaded will be copy into your
\UploadFiles directory.

See value of uploadedFile variable in above sample:

C:\Testing\UploadFiles\mcts.JPG



否则,如果您不将其复制到地图服务器中
发布应用程序后,您会遇到
错误.

希望对您有所帮助.


请记住,如果有帮助,请将其标记为答案;如果没有帮助,则将其取消标记.


问候,

代数



Otherwise if you do not copy this into you map server
after publishing your application you will encounter
an error.

Hope this could help.


Please remember to mark the replies as answers if they help and unmark them if they provide no help.


Regards,

Algem



文件上传程序不会返回删除路径的斜杠,它们可能会导致您检索路径的错误.您应该知道您的应用程序将文件保存在什么地方,如果这样,获取完整的路径名很容易,

file uploader do not returns path removing path slashes, they way you are retrieving path might me wrong.You should know where your application is saving files, if so getting full path name is easy,
String filename=fileup1.PostedFile.FileName;


这实际上返回了客户端文件名.表示指定文件的路径.
假设您的应用将所有文件保存在服务器的C:\ UPLOADED_FILES \下.
那么完整的文件名将是


this actually returns the client filename. Meaning the path to the specified file.
Supposed your app save all files under C:\UPLOADED_FILES\ in server.
then full file name will be

String filename="C:\UPLOADED_FILES\"+fileup1.PostedFile.FileName;


所以您现在拥有完整的路径.


so you have the full path now.