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 have a document library with a custom column. I want to add a file programatically, as well as a value for the custom column. I am posting the file via an ASP.NET application page. Here is what I have:

HttpPostedFile file = Request.Files["MyFile"];
web.AllowUnsafeUpdates = true;
SPFolder library = web.Folders["MyLibrary"];
SPFile spFile = library.Files.Add(file.FileName, file.InputStream);
/* The next two lines are an attempt to add the custom column value */
spFile.Item["CustomColumn"] = "CustomColumnValue";
spFile.Update();
library.Update();
web.AllowUnsafeUpdates = false;

It does add the file to the document library, but it does not add the value for the custom column. What am I doing wrong?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I found out what I was going wrong.

Instead of:

spFile.Item["CustomColumn"] = "CustomColumnValue";
spFile.Update();

do this:

spFile.Item.Properties["CustomColumn"] = "CustomColumnValue";
spFile.Item.SystemUpdate();
spFile.Update();
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.