0

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

                Hashtable objhash = new Hashtable();
                objhash.Add("List ID", ListIDNo);
                //
                try
                {
                    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));
                            filestream.Close();

                            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);
                                    myfolder.Update();
                                    file.Item.SystemUpdate(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 ?

Thanks

0

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.

Thanks

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.