Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

error uploading document

$
0
0

Hi all,

iam using below code to update the doc lib item data withattachment.But document is not updating.Iam using file upload control in my webpart.

protected void btnUpdate_Click(object sender, EventArgs e)
        {

            string DocumentID = Page.Request.QueryString["DocID"].ToString();
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
                {
                    using (SPWeb oWeb = oSite.OpenWeb())
                    {

                        SPDocumentLibrary mylist = oWeb.Lists["UploadDocument"] as SPDocumentLibrary;
                        SPQuery query = new SPQuery();
                        query.Query = "<Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + DocumentID + "</Value></Eq></Where>";
                        oWeb.AllowUnsafeUpdates = true;
                        SPListItemCollection ilistItems = mylist.GetItems(query);
                        if (ilistItems.Count > 0)
                        {
                            foreach (SPListItem oSPListItem in ilistItems)
                            {

                               //facing issue below code
                                string fileName = System.IO.Path.GetFileName(fileAttachment.PostedFile.FileName);
                                string fileExtension = fileAttachment.FileName.Substring(fileAttachment.FileName.IndexOf("."));
                                byte[] fileBytes = fileAttachment.FileBytes;
                                string athr = string.Empty;
                                string destUrl = mylist.RootFolder.Url + "/" + fileName;
                                SPFile destFile = mylist.RootFolder.Files.Add(destUrl, fileBytes, true);
                                oSPListItem["Name"] = fileName;





                                  // below code is working fine
                                oSPListItem["abc"] = drpSite.SelectedItem.Text;
                                oSPListItem["xyz"] = drpSubsite.SelectedItem.Text;
                               oSPListItem["ass"] = txtNumericInput.Text;
                                //oSPListItem["tech"] = txtTech.Text;

                                SPFieldUserValueCollection values = new SPFieldUserValueCollection();
                                if (PeopleEditor3.ResolvedEntities.Count > 0)
                                {
                                    for (int i = 0; i < PeopleEditor3.ResolvedEntities.Count; i++)
                                    {
                                        PickerEntity user = (PickerEntity)PeopleEditor3.ResolvedEntities[i];

                                        SPUser webUser = oWeb.EnsureUser(user.Key);
                                        SPFieldUserValue userValue = new SPFieldUserValue(oWeb, webUser.ID, webUser.Name);


                                        SPUser myUser = userValue.User;
                                        string myUser1 = myUser.Name;


                                        oSPListItem.Fields["User"].ReadOnlyField = false;

                                        oSPListItem["User"] = myUser1;

                                    }
                                }


                                oSPListItem["accd"] = txtBU.Text;

                                oSPListItem.Update();
                            }
                        }



                        oWeb.AllowUnsafeUpdates = false;

                    }
                }
            });




        }



below error is coming

The specified name is already in use.

The document or folder name was not changed.  To change the name to a different value, close this dialog and edit the properties of the document or folder.please help.

regards,

praveen

                                                                                                                     

Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>