SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am uploading a document in the document library using the following code.

                Hashtable objhash = new Hashtable();
                objhash.Add("List ID", ListIDNo);
                    if (FileUpload1.PostedFile != null)
                        if (FileUpload1.PostedFile.ContentLength > 0)

                            Stream filestream = FileUpload1.PostedFile.InputStream;
                            byte[] byt = new byte[Convert.ToInt32(FileUpload1.PostedFile.ContentLength)];
                            filestream.Read(byt, 0, Convert.ToInt32(FileUpload1.PostedFile.ContentLength));

                            using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                                using (SPWeb webcollection = site.OpenWeb())

                                    SPFolder myfolder = webcollection.Folders["Contract Forms"];
                                    webcollection.AllowUnsafeUpdates = true;
                                    //myfolder.Files.Add(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName), byt, objhash, false);

                                    SPFile file;
                                    file = myfolder.Files.Add(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName), byt,objhash, false);

This works fine when we upload the document to the Document Library. When the document is uploaded the version shows as 0.1 and when the item is edited and add some fields into it the version changes as 0.2. Whenever i click edit and save it the version is updated. I want the version to change only when i edit the document. while uploading the document i am also updating a field in the document library using hash table. Any Ideas ?


share|improve this question
up vote 0 down vote accepted

I have figured out this problem. Since we not using the default method for uploading the document to the document library we have to use custom document library for this purpose. I have used custom task form in order to upload the document to the document library and so the document library also has to be custom document library. Hope this helps someone.


share|improve this answer

Your Answer


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.