2

I refer several blogs for this issue , they said there will be a column named as EncodedAbsUrl for the document set but I can't find that column.

How can I get the URI to the document?

Robert Lindgren
  • 24,520
  • 12
  • 53
  • 79
user27178
  • 372
  • 1
  • 5
  • 18

1 Answers1

1

With client object model use :

string server = site Url ;
            var context = new ClientContext(server);
            var web = context.Web;
            List list = web.Lists.GetByTitle("text");
            ListItemCollection objListItemCollection = list.GetItems(new CamlQuery());
            context.Load(objListItemCollection,
items => items.Include(item => item.Id,
item => item["FileLeafRef"],
item => item["LinkFilename"],
item => item["FileRef"],
item => item["EncodedAbsUrl"],
item => item["DocIcon"]));

            context.ExecuteQuery();

            foreach(ListItem item in objListItemCollection)
            {
                string fileUrl = item["EncodedAbsUrl"].ToString();

            }

You can modify the code as per your requirement.

You can get the absolute URL with the following code in server object model

SPListItem item = your item;
string absUrl = (string) item[SPBuiltInFieldId.EncodedAbsUrl];

For SPFile object:

SPFile file = your file object;
 string absUrl = (string) file.Item[SPBuiltInFieldId.EncodedAbsUrl];

Also check: https://stackoverflow.com/questions/5216832/how-to-get-the-absolute-url-of-a-file-in-sharepoint-library

Aanchal
  • 7,885
  • 1
  • 15
  • 20