C# 如何以相对url格式获取Sharepoint图像

C# 如何以相对url格式获取Sharepoint图像,c#,asp.net,sharepoint,C#,Asp.net,Sharepoint,我有一个返回完整图像url的SPListItem: http://sharepointsite.com/images/bob的图片.jpg 我通过调用以下命令返回此url: splistitem.File.ServerRelativeUrl 我希望能够将此url转换为: http://sharepointsite.com/images/bob%27s%20picture.jpg 但是如果我对完整的URL进行编码,它将替换我不想要的/。我希望能够获取结束图像文件并对其进行URL编码,我将如何以程序

我有一个返回完整图像url的SPListItem:

http://sharepointsite.com/images/bob的图片.jpg

我通过调用以下命令返回此url:

splistitem.File.ServerRelativeUrl

我希望能够将此url转换为:

http://sharepointsite.com/images/bob%27s%20picture.jpg

但是如果我对完整的URL进行编码,它将替换我不想要的
/
。我希望能够获取结束图像文件并对其进行URL编码,我将如何以程序方式解决此问题?

尝试以下方法:

 var url = "http://sharepointsite.com/images/bob's picture.jpg";
 var basePath = System.IO.Path.GetDirectoryName(url);
 var fileName = System.IO.Path.GetFileName(url);
 var finalPath = basePath + "\\" + Uri.EscapeDataString(fileName);
试试这个:

 var url = "http://sharepointsite.com/images/bob's picture.jpg";
 var basePath = System.IO.Path.GetDirectoryName(url);
 var fileName = System.IO.Path.GetFileName(url);
 var finalPath = basePath + "\\" + Uri.EscapeDataString(fileName);

您只需调用
splistitem.File[SPBuiltInFieldId.EncodedAbsUrl]
即可实现这一点-它不会替换正斜杠。然后,如果只需要文件名,可以将其传递到
System.IO.Path.GetFileName


顺便问一下,ServerRelativeUrl是否应该返回/images/bob's picture.jpg?

您只需调用
splistitem.File[SPBuiltInFieldId.EncodedAbsUrl]
即可实现这一点-它不会取代前斜杠。然后,如果只需要文件名,可以将其传递到
System.IO.Path.GetFileName

顺便问一下,你不应该返回/images/bob's picture.jpg吗