SheDezy

I'm uploading documents to a document library using the following code:

<%@ WebService Language="C#" Class="UploadService.Files" %>

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;
using System.IO;
using System.Web.Services;

[WebService(Namespace = "Microsoft.SharePoint.Administration")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Files : System.Web.Services.WebService

{

[WebMethod]
public string UploadDocument(string fileName, byte[] fileContents, string pathFolder)
{
if (fileContents == null)
{
return "Null Attachment";
}
try
{

SPSite site = new SPSite("http://ussrm-wsf:25594/Docs/default.aspx");
SPWeb web = site.OpenWeb();

SPFolder objFolder = myWeb.GetFolder("IBM Reports");
string fileURL = fileName;
byte[] myFile = new byte[1000];
FileStream mystream = new System.IO.FileStream(strFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
mystream.Read(myFile, 0, 1000);
mystream.Close();
SPFile file = folder.Files.Add(fileURL, fileContents, true);
return file.TimeCreated.ToLongDateString() + "::" + file.Title;

}
catch (System.Exception ex)
{
return ex.Message + "::" + ex.Source;
}
}

}




What I want to do is enter data for the column names. For example, I have a column named ColXYZ and I want it to read "cheeseburger" when I upload a document. How do I do this


Re: SharePoint - Development and Programming changing column names in sharepoint 3.0 document library

ChrisF

You can use the static SPListItem.Copy method for this. The hashtable's contents seem to need a string key (the name of the column) and a SPCopyFieldInformation value. If you use reflector to look at the SharePoint Copy web service you can see that it uses this method.





Re: SharePoint - Development and Programming changing column names in sharepoint 3.0 document library

SheDezy

Isn't SPListItem.Copy just for moving docs from one library to another




Re: SharePoint - Development and Programming changing column names in sharepoint 3.0 document library

Curtis Ruppe

After you create the file object, simply run

Code Snippet

file.Item["ColXYZ"] = "I CAN HAS CHEEZBURGER ";

file.Item.Update();

...or something similar.

http://lolcode.com/ (In case you didn't get the joke).





Re: SharePoint - Development and Programming changing column names in sharepoint 3.0 document library

ChrisF

That will work, but it'll change the document version.





Re: SharePoint - Development and Programming changing column names in sharepoint 3.0 document library

Curtis Ruppe (MicroStaff IT)

Okay, then use this...

Code Snippet

file.Item["ColXYZ"] = "I CAN HAS CHEEZBURGER ";

file.Item.UpdateOverwriteVersion();





Re: SharePoint - Development and Programming changing column names in sharepoint 3.0 document library

ChrisF

Hey, thanks. I didn't even know that method existed. A bit easier than the hassle of my method...