How to get the metadata of a file in SharePoint

7.2k views Asked by At

I am trying to get the name property of a file on SharePoint ?

If I try to get the metadata of the columns I created, I can get this data with this method

file is SPFile.

if (file.GetProperty("DocId") != null)
{
    docId = file.GetProperty("DocId").ToString();
}

But when I try to get the name

if (file.GetProperty("Name") != null)
{
    docId = file.GetProperty("Name").ToString();
}
else {...}

it goes to else statement.

Where do I go wrong?

Thanks.

2

There are 2 answers

0
kevin On BEST ANSWER

It's OK after I use

file.Item.Name;
1
Alexei Levenkov On

Most likely you want to look at properties of an SPItem associated with the SPFile in a document library - SPFile.GetListItem.

You can also enumerate all properties of the file with SPFile.Properties to see that name of "file name" property is something like "vti_title".