1

I am currently working with Document Library. And I am using Custom solution for add and remove documents in the Library. My custom page has following options to store a document in the Library. Upload Document in the Library

When I upload file with meta information in the Library and I am only able to update Meta information only for that item.

I don't know how upload new file for the same item. please help me if anyone know about this........ Edit Document

Please provide code for solve this problem.......

1
  • Any particular reason for using the custom code... OOTB form can also help Commented Oct 26, 2016 at 5:31

2 Answers 2

1

You can check the file.Exists property. The usage is as below:

using (SPSite site = new SPSite("http://server/site"))
using (SPWeb web = site.OpenWeb())
{
  SPFile file = web.GetFile("/site/doclib/folder/filename.ext");
  if (file.Exists)
  {
    //update only metadata
  }
  else
  { 
    //your original code to upload file
  }
}
1
  • I think in this case a new item will be added in the RootFolder, so I have to enter metadata information for that but I only want to update file associated with any itemID that previously available in the List and already have some meta information in it. So please tell how to upload new file that replace previous file and should be associated with previous file metadata information. Commented Oct 26, 2016 at 9:15
0

For document library, upload = New Item action & Updating metadata = Edit Item. So you need to capture the new item action, get the related item ID and call the update action for updating metadata.

4
  • I think in this case a new item will be added in the RootFolder, so I have to enter metadata information for that but I only want to update file associated with any itemID that previously available in the List and already have some meta information in it. So please tell how to upload new file that replace previous file and should be associated with previous file metadata information. Commented Oct 26, 2016 at 8:16
  • First option is to upload the same file again, then check if file exist, if exist then override the file and load the existing metadata. If required user can change and click on save. Commented Oct 26, 2016 at 8:20
  • Please provide any second option, because I want to update previous file by uploading new file not same file. Commented Oct 26, 2016 at 8:33
  • you can upload the same file means - File name remains same, but content could be changed. That way the code will check of existing file name and load the metadata for it. 2nd method would be to provide the view of all existing file with link to 'Edit" / "Update". Then load the web part with existing metadata and allow user to change info and then save it. Commented Oct 26, 2016 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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