Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am going through a code which is trying to make URL for a document within a document library,

string mydocumentpath = "https://" + spSite.HostName +
 MyDocumentlibrary.RootFolder.ServerRelativeUrl;

string mySecretEncodedPath = HttpUtility.UrlPathEncode(mydocumentpath ) + "/";

I am bit confused with where this root folder came from and what does "ServerRelativeUrl" is doing here, I already read this microsoft.sharepoint.splist.rootfolder.aspx but couldn't get answer I want.

Also is it alright to change root folder name ?

if it is then what would be the best way of doing it.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

The url that you are generating with that code is in the form

http://MySite/MyLibrary

http:// + spSite.hostname can be replaced with spSite.Url to get the same effect.

ServerRelativeUrl is the part of the url after MySite so in this case it is just MyLibrary. MySite is the server or root.

The root folder of a library is the folder that is located at

http://MySite/MyLibrary 

any other folder you create in the library would have the url

http://MySite/MyLibrar/OtherFolder

You can rename the root folder by renaming the library because they are one and the same thing. Think of the library itself as a folder with certain properties that an ordinary folder doesn't have.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.