Update document library item where a docx document uploaded using powershell script

HI
when i update an existing item of a document library using script i faced the issue.
i uploaded two .txt files and two word docx files and a png file.
where i update .txt file item there is no issues , but  for other items i have problem.
PS C:\Scripts> C:\Scripts\UPdateDocLibrary.ps1
Exception calling "Update" with "0" argument(s): "There is no file with URL 'Do
cs/Emc.docx' in this Web."
At C:\Scripts\UPdateDocLibrary.ps1:26 char:13
+ $item.Update <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
$webURL = "http://tspmcwfe:89"
$listName = "Docs"
#Get the SPWeb object and save it to a variable
$web = Get-SPWeb $webURL
#Get the SPList object to retrieve the "Demo List"
$list = $web.Lists[$listName]
$items = $list.items
#Go through all items
foreach($item in $items)
if($item["NO"] -eq $null)
$item["Title"] = "My updated edited item!"
$item.Update()
adil

Please check if file is checkout or locked , and if not then checkout it and then try to update -
$url= $webURL + $item.File.Url;
$file = $web.GetFile($url);
if($file.CheckOutType -eq "None" -And $file.LockType -eq "None")
$file.CheckOut();
also please try these option, may help -
1. Allow unsafe update at web
$web.AllowUnsafeUpdates=$true;
2. try systemupdate
$item.SystemUpdate($false)
Thanks
Ganesh Jat [My Blog |
LinkedIn | Twitter ]
Please click 'Mark As Answer' if a post solves your problem or 'Vote As Helpful' if it was useful.

Similar Messages

  • How to set Document Library Item Limit at Site Collection level?

    Hi,
    I have SharePoint which contains one Site collection with many Sites. Each sites has many document library.
    Actually my requirement is, End Users  wants to see only 10 items per page in document library. We can manually set by using "Item Limit" option but i could not set that for around 150 document libraries.
    Is there any possible to set that in Site Collection level?
    Thanks & Regards
    Poomani Sankaran

    You can run for each loop and use below code
    http://get-spscripts.com/
    #Get the site and list
    $web = Get-SPWeb "http://portal/sites/testsite"
    $list = $web.GetList(($web.ServerRelativeUrl.TrimEnd("/") + "/Shared Documents"))
    #Get the list view to be changed
    $newview = $list.Views["Sort by modified date"]
    #Set the mobile and default mobile view properties
    $newview.MobileView = $true
    $newview.MobileDefaultView = $true
    #Update the view configuration
    $newview.Update()
    $web.Dispose()
    $web.Lists[0].Views[0].RowLimit=30
    $web.Lists[0].Views[0].Update()
    How you can get all list using powershell
    http://sharepointrelated.com/2011/11/28/get-all-sharepoint-lists-by-using-powershell/
    If this helped you resolve your issue, please mark it Answered

  • SharePoint 2013 : Add annotation to document library item

    Hi all,
    Is there a possibility to add annotation to library items. Example, I am sharing a document library item to a user then the user add an annotation and share to another user.  The other user also should add his/her comments on the item.
    Can anyone help me how to achieve this?
    Many thanks & regards
    Vinay

    We've done this in the past using a Rich Text Field in the metadata of the document.  You can set it up so it Appends new entries to the bottom of the field instead of replacing the existing content.  When a user edits the metadata they see a
    blank field.  When they save it their comments are added to the bottom with their name and a timestamp.  We've used it primarily on issues lists, but it should work on a document also.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Document Library + Items Color

    Hi All,
    Welcome to SharePoint products & Technologies.
    How to Change the color of the Document library items based on the field values? for eg., I have a column called "Status", based on this field values the color of the items should change accordingly.
    Can any one help me out on this issue.
    Let me know if you are not clear or need more information
    Regards,
    SpUser.

    Hi,
    Sorry for the late reply .Could not check the blogs.Here is the script to be put in content editor webpart:-
    <script language="javascript" type="text/javascript">
      var x = document.getElementsByTagName("td") // find all of the TDs
      var i=0;
      for (i=0;i<x.length;i++)
        if (x[i].className=="ms-vb2") //find the TDs styled for lists
          if (x[i].innerHTML=="In Process")
            x[i].parentNode.style.backgroundColor='lightyellow'; // set the color
    if (x[i].innerHTML=="Accepted")
            x[i].parentNode.style.backgroundColor='lightgreen'; // set the color
    if (x[i].innerHTML=="Not Accepted")
            x[i].parentNode.style.backgroundColor='red'; // set the color
    if (x[i].innerHTML=="Need More Info")
            x[i].parentNode.style.backgroundColor='lightblue'; // set the color
      } </script>

  • Convert list item attachment from docx to pdf using Word Automation Services

    I have been trying to convert List Item attachments from docx to pdf using word automation services, it works in a normal document library but when I use the list attachment it throws a null reference error.
    var settings = new ConversionJobSettings();
    settings.OutputFormat = Microsoft.Office.Word.Server.Conversions.SaveFormat.PDF;
    var conversion = new ConversionJob("Word Automation Services", settings);
    conversion.UserToken = SPContext.Current.Site.UserToken;
    var wordFile = SPContext.Current.Site.RootWeb.Url + "/" + wordForm.Url;
    var pdfFile = wordFile.Replace(".docx", ".pdf");
    conversion.AddFile(wordFile, pdfFile);
    conversion.Start();
    Using reflector I was able to see my problem lies in Microsoft.Office.Word.Server.FolderIterator.cs where it uses SPFile.Item which returns NULL
    internal void CheckSingleItem(SPFile inputFile, SPFile outputFile)
    Microsoft.Office.Word.Server.Log.TraceTag(0x67337931, Microsoft.Office.Word.Server.Log.Category.ObjectModel, Microsoft.Office.Word.Server.Log.Level.Verbose, "OM: FolderIterator start a single item: source='{0}'; dest='{1}'", new object[] { inputFile.Url, outputFile.Url });
    Stopwatch stopwatch = Microsoft.Office.Word.Server.Log.StartPerfStopwatch();
    try
    this.CheckInputFile(inputFile.Item);
    this.CheckOutputFile(outputFile.Url);
    Is there any way to get around this?

    Hi Qfroth,
    According to your description, my understanding is that when you use word automation service to convert Word to PDF for list item attachment, it throws the null reference error.
    I suggest you can create an event receiver and convert the word to memory stream like below:
    private byte[] ConvertWordToPDF(SPFile spFile, SPUserToken usrToken)
    byte[] result = null;
    try
    using (Stream read = spFile.OpenBinaryStream())
    using (MemoryStream write = new MemoryStream())
    // Initialise Word Automation Service
    SyncConverter sc = new SyncConverter(WORD_AUTOMATION_SERVICE);
    sc.UserToken = usrToken;
    sc.Settings.UpdateFields = true;
    sc.Settings.OutputFormat = SaveFormat.PDF;
    // Convert to PDF
    ConversionItemInfo info = sc.Convert(read, write);
    if (info.Succeeded)
    result = write.ToArray();
    catch (Exception ex)
    // Do your error management here.
    return result;
    Here is a detailed code demo for your reference:
    Word to PDF Conversion using Word Automation Service
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • Sharepoint 2013 / Office 365 Document library item level permissions problem

    Hello,
    I'm looking for a solution to enable users to upload documents to a document library, the ability to view other documents uploaded to the same document library, but able to edit or delete those other documents.
    With a list you can use Item-Level security in Advanced Settings but this is not available for Document libraries. I could use workflows to assign individual permissions to document, but the the library already contains over 2,000 documents and will continue
    to expand so I don't like the idea of having that many individual permissions set.
    Are there any 3rd party plug-ins or solutions to this issue?
    Thanks,

    Try below:
    http://www.hersheytech.com/Blog/SharePoint/tabid/197/entryid/28/Default.aspx
    As it turns out the, setting Item-Level Permissions in a library is fully supported with PowerShell!
    The PowerShell commands for changing this are very simple:
    $web = Get-SPWeb http://YourSite/
    $list = $web.Lists[“Your Document Library Name”]
    $list.ReadSecurity = 2
    $list.Update()
    $web.Dispose()
    Note the 3rd line which is where you determine the value for this setting using the following values:
    1 = “Read all items”
    2 = “Read items that were created by the user”
    If you wish to modify the values for Create and Edit access instead, replace .ReadSecurity with .WriteSecurity with
    the following values:
    1 = “Create and edit All items”
    2 = “Create items and edit items that were created by the user”
    4 = “None”
    For example:
    $web = Get-SPWeb http://YourSite/
    $list = $web.Lists[“Your Document Library Name”]
    $list.WriteSecurity = 2
    $list.Update()
    $web.Dispose()
    Also check 
    http://sppermissions.codeplex.com/
    If this helped you resolve your issue, please mark it Answered. You can reach me through http://freeit-support.com/

  • Writing modified date of a document library item through CSOM.

    I´m working on an application which is replicating files from one document library to another. Since it is a replication, I want the modified date to be preserved when I copy the file from the source library to the target, so that the user will see the real
    modified date in the target library and not the date of the replication run.
    I access SharePoint through the client side object model and I have been able to set the modified date on a SharePoint 2010 on-premise using the following straght-forward code:
    var listItem = list.GetItemById(id);
    context.Load(listItem);
    context.ExecuteQuery();
    listItem["Modified"] = "03/11/1999";
    listItem.Update();
    context.ExecuteQuery();
    Unfortunately when I execute the same code on any other SharePoint (2013 On-Premise, 2013 Online or 2010 Online) the code will execute without any errors, but the modified date will not be changed at all.
    My actual question is: Is there any possibility to change the modified date throught CSOM on all of these SharePoint-versions?

    I got a work around for this problem..
    Before updating the Modified, Modified By values, First we need to Disable the version settings for document library. Once the fields updated then again we need to enable the version settings. 
    find the updated code below..
                                          //Disable Version settings for DOC LIB
    before update Metadata
                                            _List.EnableVersioning
    = false;
                                            _List.Update();
                                            _cContext.ExecuteQuery();
                                           ListItem item = newFile.ListItemAllFields;
                                           _cContext.Load(item);
                                            //Updating Metadata Created,
    CreatedBy, Modified, Modified By
                                             item["Created"]
    = "8/10/2013 7:04 PM";
                                             item["Author"] = CreatedUserValue;
                                             item["Modified"] = "8/10/2013 7:04 PM";
                                             item["Editor"] = ModifiedUserValue;
                                             item.Update();
                                            _cContext.ExecuteQuery();
                                            //Enable Version settings
    for DOC LIB after update Metadata
                                               _List.EnableVersioning
    = true;
                                              _List.Update();
                                            _cContext.ExecuteQuery();
    Rajendra

  • Not able to create sub folder using SharePoint web service in large SharePoint document library (Item count view threshold limit)

    We are trying to create folder & subfolder in a SharePoint document library using SharePoint default(dws) web service. Document library has unique permission as well as item level permission. It was working as expected. Once item count crosses
    view threshold limit ( 5000) , create folder web method completes with an error and it creates a folder in SharePoint.
    Request:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dws="http://schemas.microsoft.com/sharepoint/soap/dws/">
       <soapenv:Header/>
       <soapenv:Body>
          <dws:CreateFolder>
             <!--Optional:-->
             <dws:url>Shared Documents/VenTest02092015v1</dws:url>
          </dws:CreateFolder>
       </soapenv:Body>
    </soapenv:Envelope>
     Response:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
          <CreateFolderResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/dws/">
             <CreateFolderResult>&lt;Error ID="2">Failed&lt;/Error></CreateFolderResult>
          </CreateFolderResponse>
       </soap:Body>
    </soap:Envelope>
     While trying to create subfolder under the above created folder service throws an exception saying
    FolderNotFound.
    Though we are able to create subfolder from SharePoint UI successfully. 
    Request
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dws="http://schemas.microsoft.com/sharepoint/soap/dws/">
       <soapenv:Header/>
       <soapenv:Body>
          <dws:CreateFolder>
             <!--Optional:-->
             <dws:url>Shared Documents/VenTest02092015v1/REQ-1</dws:url>
          </dws:CreateFolder>
       </soapenv:Body>
    </soapenv:Envelope>
    Response:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
          <CreateFolderResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/dws/">
             <CreateFolderResult>&lt;Error ID="10">FolderNotFound&lt;/Error></CreateFolderResult>
          </CreateFolderResponse>
       </soap:Body>
    </soap:Envelope>

    Yes, you're probably hitting the 5000 list item threshold (
    http://sharepoint.stackexchange.com/questions/105937/overcoming-5000-file-document-library-limits ). I assume you can do it via the UI because you're probably logged in as an admin in which case, out of memory, the threshold is 20.000 items. You can extend
    this limit, but you probably shouldn't.
    Kind regards,
    Margriet Bruggeman
    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • Document library items are not displaying in sorted order in sharepoint 2013

    Hi,
    I have a document library , I am storing document sets on it.
    28326 items are there in the library.
    I have configured sort on Name columns. Initially items are displaying in sorted order like (A,B,C,D,E...)
    Now Items are not displaying in a sorted order it is displaying like (A, B,C,D,E,A,C...) like this.
    Please help me on this sorting issue.
    Thanks,
    Samir

    Are the documents displaying in your image inside the document sets?  If so then your sets (folders) are displaying in alphabetical order and the documents inside the sets are displaying in alphabetical order.  This is what i would expect.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Document Library items delete

    Hi ,
    I have a Document Library. I created one custom view through code.
    in that, i need to show a DELETE option. i already did that.
    Question is, only document owners only should have the right to delete those doc's. Others should not delete.
    For a list, we have ITEM LEVEL PERMISSION option. Like that , is there any way to achieve  that?
    How to do that.?

    Hello,
    Just create a designer workflow for  your requirement.
    Execute that workflow when an new document gets added under library.
    The functionality of the workflow is as follows
    When a new document get added, you workflow will set contribute access to the owner of that document and will set read access to rest all other users.

  • Workflow in document library doesn't function properly on uploaded documents

    I have a document library with a few different content types. When documents are added to the library either via new or upload I want to run a workflow that numbers the documents (so contracts have a contract number & change orders have an order number).
    The counters are in a separate list - one item for each counter, a last number and a calculated next number.
    So for contract numbers the workflow gets the nextnumber for the counter and enters it into the contract number field of the current item before sending it back to the counter as last number. 
    The workflow is set to start on item creation and works just fine with new documents. However, it doesn't work on uploaded documents. In order to discern between the different content types I've set a field condition to recognize if the workflow should run.
    When uploading documents the workflow runs before the field is set and therefore doesn't set the contract number. 
    I tried just setting a 5 min "wait" at the start of the workflow, but then the document fails to save. 
    Workflow:
    Sorry it's in Norwegian, I can't figure out how to get the conditions and actions into English (all my buttons etc are in English)...
    Any ideas on how to get the workflow to run properly in order to update the contract number?

    Hi,
    According to your post, my understanding is that you had a workflow in document library didn’t work properly.
    I hadcreated a list called Counter1, created a library called
    New&Upload, modified the view of the list, made it display the
    ID of the list.
    I created a simple workflow as below, selected “Start workflow automatically when an item is created”, it worked well without any issue no matter
    Upload or New a document.
    You can create a new workflow with a new library, then check whether it works.
    You can also check the event log and ULS log to see if anything unexpected occurred.
    To check event log, click the Start button and type “Event Viewer” in the Search box.
    For SharePoint 2013, by default, ULS log is at      
    C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\LOGS
    You can check the ULS log by the methods here:
    http://blogs.msdn.com/b/opal/archive/2009/12/22/uls-viewer-for-sharepoint-2010-troubleshooting.aspx
    http://msdn.microsoft.com/en-us/library/gg193966(v=office.14).aspx
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Using Content Query webpart for specific Document library with multiple managed metadata - Document with multiple metadata tags not showing up

    Hi,
    I am having an issue where when I insert a Content Query webpart into a page, and filter to managed metadata, all the right documents show up except one document that happens to have two metadata tags attached to it.  The content query webpart is set
    to only look through a specific document library.  I'm not sure what I am doing wrong.
    Here is the one document with two metadata tags:
    Below is the Content Query:

    Hi,
    As I understand, you did not get the results with multiple metadata tags through Content Query web part in SharePoint 2013.
    Check things below:
    1. Check if you have set the item limit more than the display items in Presentation section of the web part. If the item number more than item limit, the rest items will not show.
    2. Check if the item you cannot find uses the content type you have set in the content type section of content query web part.
    When you edit the properties of the item, you will see the content type the item is using.
    Best regards
    Sara Fan
    TechNet Community Support

  • Document line item text in Clearing document

    Dear All,
    Document line item text
    My client want the vendor invoice line item text(BSIK-SGTXT) to be captured in the corresponding clearing document line item text field(BSAK-SGTXT).
    (i.e) The vendor invoice and its payment clearing document should have the same text in the document line item text filed.
    According to me i can use  a substition rule and a user exit to assign the values. but here comes a problem* i have one clearing document against 3 to 4 vendor invoice documents* so my programming logic has got stucked here? like which vendor invoice line item text the clearing document should pick up?
    is there any other enhancements possible or can some one help me with the programming logic to be applied here.
    Thank you
    Regards,
    Vasanth D

    like which vendor invoice line item text the clearing document should pick up?
    is there any other enhancements possible or can some one help me with the programming logic to be applied here
    Why don't you discuss the issue with your client?  As you said, if you pay 5 invoices in a single run, the payment document item text can't carry all of those texts unless you use the long text.  What is the reason for the requirement?  Perhaps there's another solution.

  • SD document line items Vs FICA accounting document line items

    Hello All,
    What is the interface we use in SAP,  between the SD and FICA which will determine line items in FICA document with regard to SD line items.
    SD : How we do configuration or mapping between sd sales order and billing document to determine billing document line items  based on sales order line items ( for example : material group, profit center, cost center ?)
    FICA: what interface / Configuration we use to determine how many line items should appear in the FICA document based on billing document line items.
    Regards,
    John.

    Integeration of SD to FICA is based on the img settings done under the node - SPRO - Financial accounting ( new ) - Contract accounts receivable and payable - integration - Sales and distribution .
    Creation of FICA document based on SD is routed through the event 4000 and the details are detrived through event 4030 .
    Would suggest you to go through events 4000 and 4030 .
    Regards ,
    Dewang

  • Uploaded document via windows application does not show in document library, but as checked out Document

    Hi,
    A windows application uploads document to a document library programatically. Although they get added to the document library but are not shown there. Only when I go to the "Managed file that have no checked in verison" I see all the documents.
    This happens even though I have set "No Versioning" in the library settings. This is probably happening because I have added a few custom columns to the library.
    How can I avoid this situation and get to upload document which can directly be seen on the document library rather than first taking control of the doc and then checking it in?

    Hi,
    When uploading files without filling in some required columns, the files would appear in “Checked Out Files” page.
    To avoid this situation, you can modify that windows application to force users fill in the required columns or just define default values for those columns.
    You can take a look at the link below for more information:
    http://dlairman.wordpress.com/2013/03/13/favorite-sharepoint-feature-this-week-manage-files-which-have-no-checked-in-version/
    Best regards,
    Patrick
    Patrick Liang
    TechNet Community Support

Maybe you are looking for