急急急!!!获取文件的相对的问题

来源:百度知道 编辑:UC知道 时间:2024/09/22 11:50:07
string ImgPath=this.txtFileContents.PostedFile.FileName;
string ImgName=ImgPath.Substring(ImgPath.LastIndexOf("\\")+1);
string ServerPath = Server.MapPath("Img/") + ImgName;

这段代码中ServerPath 就是该文件的相对路径吗?但我取出的ServerPath值和绝对路径ImgPath的值是一样的,这是什么回事呢?

string path = Application.StartupPath+@"\文件名.扩展名"; Proc = System.Diagnostics.Process.Start(@path);
这就是获取相对路径了,只要把你要得到的文件放在程序的bin文件夹下就行了。

因为你没有取相对路径

Server.MapPath()这个方法是用来相对路径转绝对路径的