views:

330

answers:

1

I have a column in a SharePoint list that I wish to make a link to a file on the network. The file location is generated in code so I need to write a CAML script to update the column.

Could someone please give me an example of what the value stored in the database would be? In this example the file location is \server\folder\file.txt. I would like the textual name to be the same if possible.

+2  A: 

For your link you should use a column of the type "Hyperlink or Picture". This column type can handle a link and a description for it. To set these both values for a this field you would use the following code.

SPFieldUrlValue urlField = new SPFieldUrlValue();
urlField.Description = @"\\server\folder\file.txt";
urlField.Url = @"\\server\folder\file.txt";

yourListItem["yourLinkColumnName"] = urlField;

yourListItem.Update();

SharePoint will automatically convert the link from "\server\folder\file.txt" to "file://server/folder/file.txt". But be aware that SharePoint won't handle the permissions a user needs to access the file. It's just a link.

Flo