如何获取在服务器上运行时创建的目录的绝对路径? [英] How to get the absolute path of a directory created at runtime on server?
本文介绍了如何获取在服务器上运行时创建的目录的绝对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图获取文件的绝对路径,该文件位于我在运行时创建的服务器目录中,但是当我尝试使用FileStream的绝对路径访问该文件时,它给我一个错误,提示找不到"路径的一部分."
建议任何解决方案.
I am trying to get an absolute path to a file located on a directory at server that i create at runtime but when i try to access that file using its absolute path from FileStream then it gives me an error saying "Could not find a part of the path."
Suggest any solution.
推荐答案
尝试以下操作:
Try this:
using (FileStream fs = new FileStream(Server.MapPath("Files/MyFile.txt"))
{
.....
}
希望对您有所帮助.
Hope that helps.
但是该目录也在运行时创建,这意味着该目录未包含在我们的项目中.
应用程序中存在目录视频",但其余子目录在运行时构建,并且文件位于最后一个目录中.我只想获取其到File-Stream的绝对路径.
????
字符串file_Path = Server.MapPath("/Videos/" + logging_User.User_Id +"/" + Convert.ToInt32(Session ["ID"])+"/" + file_Name);
var fileStream = new FileStream(filePath,FileMode.Open_Or_Create);
But the directory is also created at run-time means that directory is not included in our project.
Directory "Videos" exists in the application but the rest of the sub-directories are build at run-time and a file is located in the last directory. I just want to get its absolute path to File-Stream.
????
string file_Path = Server.MapPath("/Videos/" + logged_User.User_Id + "/" + Convert.ToInt32(Session["ID"]) + "/" + file_Name);
var fileStream = new FileStream(filePath, FileMode.Open_Or_Create);
这篇关于如何获取在服务器上运行时创建的目录的绝对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文