There are many ways to upload a file using the API but finding which is the correct method takes time and effort. You first start looking for a collection to add your SPFile to. For example: You can use the SPWeb.Files or Folder.Files. The SDK use the latter
<snip>
if (oWebsite.GetFolder("Shared Documents").Exists)
{
SPFolder oFolder = oWebsite.GetFolder("Shared Documents");
oFolder.Files.Add(strFilename, binFile, true);
}
</snip>
from http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.aspx
But how do you set meta data for the SPFile. If you google this you will find people using a hashtable and passing into the SPFileCollection.Add() method. This sounds like a feasible method, the code looks something like:
// add the metadata to File
Hashtable metaData
metaData.Add("Title", "My Title");
// put on your destination file
SPFileCollection destFiles = web.GetFolder([Folder]).Files;
destFiles.Add(Path.GetFileName(inputFile.PostedFile.FileName), inputFile.PostedFile.InputStream, metaData, true);
You would expect this to set the title field for the document. This isn't the case. The title field is actually called vti_Title if you look at the underlying names for the SPFile.Properties collection. I wrote a simple app to check the values of an existing document in a SharePoint library. The output was:
vti_canmaybeedit : true
_Author : Administrator
vti_timecreated : 08/12/2008 12:33:41
_Category :
_Status :
vti_timelastmodified : 08/12/2008 12:33:41
ContentType : Document
vti_title :
vti_replid : rid:{CE94E052-257E-4B95-946B-3B2B91CC0957}
vti_parserversion : 12.0.0.6219
PublishingStartDate :
vti_level : 1
vti_rtag : rt:CE94E052-257E-4B95-946B-3B2B91CC0957@00000000001
vti_sourcecontrolcookie : fp_internal
ContentTypeId : 0x0101003087515E5634704F98FD43AEB256E309
vti_docstoreversion : 1
vti_filesize : 17107
vti_sourcecontrolversion : V1.0
vti_docstoretype : 0
vti_author : DOMAIN\administrator
vti_modifiedby : DOMAIN\administrator
PublishingExpirationDate :
Because of the inconsistent naming I searched for a different approach. The SPFile has a property called "Item" which contains the SPListItem which is linked to the SPFile. You can update a SPListItem so how about if I add the file and then update the list item. Here's the code:
// add the file
SPFile file = docLib.RootFolder.Files.Add(newFileName, upload.PostedFile.InputStream);
// get the list item for that file
SPListItem item = file.Item;
item["Title"] = "My Title";
item["Another Column"] = "My Value";
item.Update();
Hope this helps
By the way: VTI is an acronym of Vermeer Technologies Incorporated, which is the company Microsoft acquired in 1996.