概述
Below you can see the path that has been stored in the database and what i need it to look like. So I can use the path to change an image.
From the Database:
C:UsersAlphaDogDesktopAlumni RevisedAlumiTrackingSystemAlumiTrackingSystemAlumiTrackingSystemAlumiTrackingSystemimageVinceTulips.jpg
Needs to be changed to:
~/image/Vince/Tulips.jpg
Talk1:
Not clear, what does the first path means? Is it where your Website is hosted?
Talk3:
The first path is the root path where I saved it from the database. Then I need to get the path from Database to change the image but it cannot be change.
Talk4:
If I understand you correctly, you want to create a virtual directory that points to image folder.
Talk5:
I think the problem is that you don't have enough repetitions of AlumniTrackingSystem in your path. I think another 2 should do the trick.
Solutions1
Something like the following should do the trick. A little more code than the previous answer, but you know, sometimes I like to do things the hard way.
string path = @"C:UsersAlphaDogDesktopAlumni RevisedAlumiTrackingSystemAlumiTrackingSystemAlumiTrackingSystemAlumiTrackingSystemimageVinceTulips.jpg";
string[] splitPath = path.Split('\');
int start = 0;
foreach (string s in splitPath) {
if (s == "image")
break;
else
start++;
}
string virtualPath = "~/";
for (int i = start; start < splitPath.Length; start++) {
virtualPath += (i > start ? "/" : "") + splitPath[start];
}
Solutions2
i hope this is what you are looking for:
String RelativePath = AbsolutePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
it should work if your app phisical path is:
C:UsersAlphaDogDesktopAlumni RevisedAlumiTrackingSystemAlumiTrackingSystemAlumiTrackingSystemAlumiTrackingSystem
最后
以上就是友好马里奥为你收集整理的c#+编码后的服务器虚拟路径,.net c#如何将物理路径转换为虚拟路径的全部内容,希望文章能够帮你解决c#+编码后的服务器虚拟路径,.net c#如何将物理路径转换为虚拟路径所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复