如何从上传的文件中获取完整路径? [英] How to get complete path from the uploaded file?
本文介绍了如何从上传的文件中获取完整路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在obout文件上传控件中获取所选文件的完整文件路径?
而不将该文件保存在任何其他文件夹中,如fileUpload1.SaveAs(Server.MapPath(Files /) + filename));
能够获取文件名但不能获取文件路径。
How to get the complete file path of the selected file in obout file upload control?
without saving that file in any other folder, like fileUpload1.SaveAs(Server.MapPath("Files/"+filename));
able to get file name but not file path.
推荐答案
System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName);
Path.GetFileName(FileUpload1.PostedFile.FileName);
System.IO.Path.GetDirectoryName(FileUpload1.PostedFile.FileName).ToString();
Convert.ToString(System.IO.Directory.GetParent(FileUpload1.PostedFile.FileName));
在你的代码上写这一行是为了满路径。 。使用它Server.MapPath
FileUpload1.SaveAs(Server.MapPath(download /+ FileUpload1.FileName));
和你想要dir信息所以写这个。 。
DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath(IMG /));
或者:---
如果你想在客户端机器上的文件位置
你可以使用
string fileLoacation = FileUpload1.PostedFile.FileName;
write this line on ur code for full path . . use it Server.MapPath
FileUpload1.SaveAs(Server.MapPath("download/" + FileUpload1.FileName));
and u want to dir info so write this . .
DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath("IMG/"));
Or:---
If you want the file location in client machine
You can use
string fileLoacation=FileUpload1.PostedFile.FileName;
imageUpload.PostedFiles [0] .SaveAs(Server.MapPath(〜/ / CMS_Images / logos.jpg));
我刚刚使用上传的文件覆盖了现有的图像(徽标)。它已经有效了。
imageUpload.PostedFiles[0].SaveAs(Server.MapPath("~/CMS_Images/logos.jpg"));
I have just overwritten the existing image(logos) with the uploasded file. It has worked.
这篇关于如何从上传的文件中获取完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文