Archive for upload document

SharePoint 2007: SPFileCollection.Add – Title is not updating

An old ghost that bothered again. We were trying to upload document along with metadata using SPFileCollection.Add Method. The issue we were facing is that “Title” column is not updated.

Our code don’t give us any error and columns other than “Title” were updated.

Hashtable itemMetaData = new

itemMetaData.Add(“Title”, “New Title”);

itemMetaData.Add(“Second_Column”, “Column_Value”);

SPFile spFile = fileColl.Add(url, content, itemMetaData, true);


We looked for internal name as it happened previously but noon. Then, comes Google and Dave Hunter solved the problem.


Add “vti_” before “Title”. So, it must be “vti_title”, instead of “Title”. Reason is that it is acronym from Vermeer Technologies Incorporated, acquired by MS in January, 1996.

Leave a Comment

SharePoint Document Upload Error: Unable to complete this operation. Please contact your administrator.


When we try to upload document / images error page appear with following extension: 

Unable to complete this operation. Please contact your administrator. 

When we try to upload text document, it worked but when we increased the sixe from 45Bytes to 450KB, it failed with the same message. 


You ran out of space either on SQL Server or on Server Machine. Created space and we were back on track.

Comments (5)

Upload file in MOSS / SharePoint using code

It is easy and simple to upload a file in the document library of MOSS / SharePoint. The code for upload the file in C# is as under: 

SPSite sp = new SPSite(“URL of the site collection”);     

SPWeb site = sp.OpenWeb();      

SPFolder folder = site.GetFolder(“Document Library Name”);     

SPFileCollection files = folder.Files; FileStream fStream = File.OpenRead(“C:\\upload.doc”); //path of the file to upload     

byte[] contents = new byte[fStream.Length];     

fStream.Read(contents, 0, (int)fStream.Length);     


Hashtable MetaDataTable = new Hashtable();     

MetaDataTable.Add(“Comments”, “Hello World”);      

SPFile currentFile = files.Add(“URL of the document library/upload.doc”, contents, MetaDataTable, true); 

You can addd the meta data as well by using Hash Table. We have populated the “Comments” column with “Hello World”. 

With or without using the following code

 SPListItem doc = currentFile.Item;  

We can do a lot of things with the uploaded file.

For more information, visit the Microsoft link. It provides more information about the error checking and other.

Comments (20)

In line code to upload (supportive) documents

 Recently we face a requirement from our client that one or more documents should be added against the documents already uploaded in the document library. We created a look up column (on the bases of “Title” field) and asked him to add as many documents as he wanted but he refused the solution giving two arguments. 

1-    Doesn’t have the time to go to the propertied page of each document and attach documents from there.

2-    Don’t want to fellow the process (first step was to upload the supportive document, write the name of the document in the title field and then, using properties of the target document, attach it using the look up column). 

So we have to device another solution and we decided to go in line code. For this, we added a hyperlink column and a look up column. The name of the look up column is “DocAttached”. We selected “Title” as a criteria and option for multiple values is checked. The name of the hyperlink column is “AttachDoc”. The value of the “AttachDoc” is populated by upload event handler. The code of the event handler is below: 

public override void ItemAdded(SPItemEventProperties properties)       


if (properties.ListItemId.Equals(null)){   

SPListItem doc = properties.ListItem;   

doc[“AttachDoc”] = “URL of the site/Upload_file.aspx?para=” + doc[“ID”] + “, Attach File”;                doc.Update();           



Above code concatenate the document ID with the URL of the page “Uploaded_file,aspx” that we have added using SharePoint Designer. Each time a document is uploaded, the value of the column “AttachDoc” is populated with a URL which has a concatenated value of the document ID. When the users click on the “Attach File” link provided in the “AttachDoc” column, the control passes to the page “Upload_file.aspx”.

The HTML and in line code for the page “Upload_file.aspx” is as under:   

<%@ Page Language=”C#” masterpagefile=”~masterurl/default.master” title=”|” inherits=”Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” meta:progid=”SharePoint.WebPartPage.Document” %>

<%@ Import Namespace=”Microsoft.SharePoint” %>

<asp:Content id=”Content1″ runat=”server” contentplaceholderid=”PlaceHolderMain”>


<META name=”WebPartPageExpansion” content=”full”>

<script runat=”server”>

SPSite sp;

            SPWeb WebSite;

            SPList DocLib;

int id = 0;


            string AddURL = “”;

string DocName = “”;

string DocTitle = “”;  


public void Page_Load(object o, EventArgs e)



            sp = new SPSite(“URL”);

            WebSite = sp.OpenWeb();

            DocLib = WebSite.Lists[“Document Library Name”];


            if (string.IsNullOrEmpty(Request.QueryString[“para”]))





            id = Convert.ToInt32(Request.QueryString[“para”]);




public void UploadFile(object o, EventArgs e)


             if (FileUpload1.HasFile)




        if (FileUpload2.HasFile)




        if (FileUpload3.HasFile)




        if (FileUpload4.HasFile)




        if (FileUpload5.HasFile)










        Response.Redirect(“Document Library URL”);


public void AttachDocument(FileUpload file)


        byte[] content = new byte[file.PostedFile.ContentLength];

        string URL = “URL of the document library/” + file.FileName;

        content = file.FileBytes;

        SPFolder DocLibFolder = WebSite.GetFolder(“DLOne”);

        SPFileCollection DocLists = DocLibFolder.Files;

        sp.AllowUnsafeUpdates = true;

        WebSite.AllowUnsafeUpdates = true;

        SPFile FileAdded = DocLists.Add(URL, content);

        SPListItem DocAdded = FileAdded.Item;

        DocName = DocAdded.Name;

        DocTitle = DocName.Substring(0, DocName.IndexOf(‘.’));

        DocAdded[“Title”] = DocTitle;


        AddURL = “;#” + DocAdded.ID + “;#” + DocTitle;

        SPView DefaultView = DocLib.DefaultView;

        SPQuery SelectQuery = new SPQuery(DefaultView);

        SelectQuery.Query = “<Where><Eq><FieldRef Name=’ID’/><Value Type=’Numeric’>” + id + “</Value></Eq></Where>”;

        SPListItemCollection SelectedDoc = DocLib.GetItems(SelectQuery);

        SPListItem doc = SelectedDoc.GetItemById(id);

        doc[“DocAttached”] += AddURL;       // “;#158;#sv002”;



public void button_Cancel(object o, EventArgs e)


  Response.Redirect(“URL of the Document Library”);








                <td><asp:FileUpload ID=”FileUpload1″ runat=”server”/></td>

                <td> </td>

                <td> </td>



                <td><asp:FileUpload ID=”FileUpload2″ runat=”server”/></td>

                <td> </td>

                <td> </td>



                <td><asp:FileUpload ID=”FileUpload3″ runat=”server”/></td>

                <td> </td>

                <td> </td>



                <td><asp:FileUpload ID=”FileUpload4″ runat=”server”/></td>

                <td> </td>

                <td> </td>



                <td><asp:FileUpload ID=”FileUpload5″ runat=”server”/></td>

                <td> </td>

                <td> </td>



                        <td>             </td>



             <td><asp:Button ID=”Button2″ runat=”server” Text=”Upload” OnClick=”UploadFile”/>

                <asp:Button ID=”Button1″ runat=”server” Text=”Cancel” OnClick=”button_Cancel”/></td>









The screen shoot of the “Upload_file.aspx” is as under: 



Comments (13)