How to get the Absolute URL of a file in sharepoin

2019-02-04 14:27发布

I am working on SharePoint 2010.I have an documentlibrary ID and document ID in that library with me.i don't have either web,site in which the document library is present.So now I have to get the Full URL of the document at runtime.How can I get it . I have tried the following.

string filepath = currentList.DefaultViewUrl + "/" + sListItem.Url;

Please answer this.

8条回答
Ridiculous、
2楼-- · 2019-02-04 15:16

For what it's worth, accessing the item.Web property means you are actually instantiating the SPWeb object which means that this should be disposed otherwise you'll be causing memory leakage.
It's a lot of overhead when there are better and quicker ways already mentioned.

I would use the BuiltInFieldId.EncodedAbsUrl approach mentioned since this gives you the easiest access to what you want.

查看更多
Fickle 薄情
3楼-- · 2019-02-04 15:23

If this is for the document library, try this one.

item.Web.Url+"/"+item.File.Url
查看更多
登录 后发表回答