I have a requirement, where I need to upload a document like invoice report to a record library programatic. I have used the same code as uploading document to a normal document library. Now the requirement is when I am uploading a same document again, I am getting the error as

The file is checked out for editing by SHAREPOINT\system.

Whereas when I am uploading existing document to a record library from the Sharepoint UI. It automatically renames the record(infact adds some random string at the end of the orginal file name). Is there a way, where I can achieve without writing lot of code? Looking for any sort of help.

  • I have tried, but that was for normal document library – suryakiran Aug 10 '12 at 10:21

At last after so much of research, I have found a solution. Create an intermediate Document library and upload document. Route the document to the record center. Check out the sample code.

string strFilename="Name of the File uploaded";
Hashtable metadata=new Hashtable("Other Meta data columns");
bool IsOverwrite="True or False to overwrite the existing file";
byte[] by_FileStream="Array bytes of the uploaded file";
bool MoveToRecordCeter="True or False To move to record center"; 
string strSPSite="<Site URL>";
string strSPRecLib="<Intermediate Doc Lib>";
string RecordCenterUri="<Record Center URL>";
using (SPSite oSite = new SPSite(strSPSite))
    SPWeb oWeb = oSite.OpenWeb();
    string strAdditionalInformation = string.Empty;
        SPList oList = oWeb.Lists.TryGetList(strSPRecLib);
        if (oList != null)
            SPFolder oFolder = oList.RootFolder;
            SPFile oFile = null;
            oFile = oFolder.Files.Add(oFolder.Url + "/" + strFilename, by_FileStream, metadata, IsOverwrite);
            if (MoveToRecordCeter && RecordCenterUri.Length > 0)
                string Offuri = RecordCenterUri.Trim();
                SPOfficialFileHost ofh = new SPOfficialFileHost();
                ofh.Action = SPOfficialFileAction.Move;
                ofh.OfficialFileName = oFile.Name;
                ofh.OfficialFileUrl = new Uri(Offuri);
                OfficialFileResult returnValue = oFile.SendToOfficialFile("Content-type", ofh, "", SPOfficialFileSubmissionMode.ExpirationPolicy, out strAdditionalInformation);
                if (returnValue != OfficialFileResult.Success)
                    throw new Exception("Error sending file to records center:" + strAdditionalInformation);
            return true;
            throw new Exception("List is not available.");
    catch (Exception ex)
        throw ex;
        if (oWeb != null)

Hope this would help some one :)

| improve this answer | |
  • BTW, There should be an additional note. I user who is moving the document to a record center(programatically) must be a member of Record Center Web Service Submitters. This is must :) – suryakiran Aug 14 '12 at 13:25

suryakiran, you need to undeclare the existing record before overwrite the file.

SPList recordList = recordWeb.Lists.TryGetList(recordLibName);

SPFile recordFile = recordWeb.GetFile(recordFileUrl);
if (recordFile.Exists && Records.IsRecord(recordFile.Item))

SPFile newRecordFile = recordList.RootFolder.Files.Add(
    sourceFile.Name, sourceFile.OpenBinary(), true);
| improve this answer | |
  • 2
    Please add details to your answer, think for yourself, would you find this answer helpful in its current form? :) Code and / or links is often very helpful – Robert Lindgren Sep 6 '13 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.