Cannot a file to document library with column validation

I have two problems
Problem#1: I can not create a file from C# code, If document library has a text column with Sharepoint column validation.
SharePoint throws exception if I invoke SPFileCollection.Add method.
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object punkFile, Int32 cbFile, Object punkFFM, PutFileOpt PutFileOpt, String
bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, Byte partitionToCheck, Int64 fragmentIdToCheck, String bstrCsvPartitionsToDelete,
String bstrLockIdMatch, String bstEtagToMatch, Int32 lockType, String lockId, Int32 minutes, Int32 fRefreshLock, Int32 bValidateReqFields, Guid gNewDocId, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage, String& pEtagReturn, Byte& piLevel,
Int32& pbIgnoredReqProps) at Microsoft.SharePoint.SPFileCollection.AddStreamOrBytesInternal(String urlOfFile, Stream file, PutFileOpt fileOpt, String createdBy, String modifiedBy, Int32 createdByID, Int32 modifiedByID, DateTime timeCreated, DateTime timeLastModified,
Object varProperties, String checkInComment, Stream formatMetadata, String lockIdMatch, String etagToMatch, SPLockType lockType, String lockId, TimeSpan lockTimeout, Boolean validateRequiredFields, SPVirusCheckStatus& virusCheckStatus, String& virusCheckMessage,
String& etagNew, Boolean& ignoredRequiredProps) at Microsoft.SharePoint.SPFileCollection.Add(String urlOfFile, Byte[] file, SPFileCollectionAddParameters parameters)
If I remove column validation, I don't get that error.
It would appear that the error is thrown internally in Sharepoint's Add API.
Not quite sure how to proceed now.
Problem#2: Even if I input a valid value in the column validation, the same error above is still thrown.
Confused................
[Update] Okay, I have found the reason for the exception (correct if I am wrong). Sharepoint File has metadata, and when I do the Add function, Sharepoint internally does a validation on the metadata and it will throw exception if not validated. That's why
validation would fail even when I am inputting some valid data in my field (because I am not sending that valid data to the Add function through metadata properties).So, my question now is:
Is it possible to prevent the validation on the metadata properties? Is there some APi for it?

I was probably not clear in my thread.
What I would want is for my code to upload the file to the server and then allow me to input my values for the metadata, THEN do the validation. Similar to how you upload a document to sharepoint library using the out-of-the-box webparts.
But, right now in my code, this is not possible. Uploading the file using the Add API will just throw an error BEFORE even allowing me to input any values for my item/file metadata. So, I am trying to find a way to upload my file without the validation (pretty
much like how microsoft does it in oob)
Not sure if this is clear enough now

Similar Messages

  • Batch uploading to a document library with content types

    Hi,
    I have a document library with two content types. Now I need to upload documents to this document library. However, if I have large number of files, then uploading through web UI is a pain as metadata will not be attached. How should I automate it  from
    my computer using powershell without relying on Administrator to run the powershell script. Or is there any other way to do it without using powershell? or  can powershell be run remotely from an end user computer?
    Note I am using SharePoint 2010.

    Hi,
    According to your post, my understanding is that you want to butch upload files to document library with content types.
    There are two good tools in CodePlex which can batch upload files with content types, you can have a look at them.
    DocMetaMan : Bulk document Upload and MetaData (Taxonomy) Setter
    SharePoint Multiple File Upload Script
    There are some third-party tools which can achieve the same scenario, you can refer to it.
    http://sharepoint.stackexchange.com/questions/74694/uploading-multiple-files-with-metadata
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Jason Guo
    TechNet Community Support

  • Issue with site template that contains a document library with a lookup column to another list

    I have a document library called Proposals with a lookup column in the same site called Document Categories (multiple values allowed).  It points to a list called document categories.  I have several sample documents in the Proposal Library that
    contain valid document categories.  When I save the site as a template and instantiate it, everything is fine.  However, when I remove the sample documents from the Proposal library and rebuild the site template, I can't get the  template to
    create another site.  I get an error Unable To Open Lookup List.
    I don't understand why I can instantiate a site from the template when there's sample data, but not when the document library containing the lookup column is empty.
    Does SharePoint 2010 site template support lookup columns?
    Why would it make a difference if the library is empty?
    Thanks

    Hi,
    According to your description, my understanding is that the error occurred when you created a site from the template with no files in the document library.
    I tested the same scenario per your post, and I can create a site from the template with no files in the document library with no errors.
    To solve this issue, I recommend to verify the things below:
    Did you save the site as a template with Include Content checked? If yes, I recommend to test if it works when saving the site as a template with Include Content unchecked.
    Test the same scenario with a new site to narrow the issue scope.
    I also recommend to 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 2010, by default, ULS log is at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\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
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • How to update managed metadata column for all file in document library using powershell

    Hi,
    How to update managed metadata column for all file in document library using powershell?
    Any help on it.
    Thanks & REgards
    Poomani Sankaran

    Hi TanPart,
    I have changed the code which you have give in order to get the files from SharePoint 2010 Foundation  Document Library.But i am getting below error in powershell.
    Property 'ListItemCollectionPosition' cannot be found on this object; make sure it exists and is settable.
    Could you tell me which is the issues in it?
    See the code below.
    $web = Get-SPWeb http://ntmoss2010:9090/Site
    $list = $web.Lists["DocLib"]
    $query = New-Object Microsoft.SharePoint.SPQuery
    $query.ViewAttributes = "Scope='Recursive'";
    $query.RowLimit = 2000
    $caml = '<Where><Contains><FieldRef Name="Title" /><Value Type="Text">Process Documents/Delivery</Value></Contains></Where>' +
            '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>'
    $query.Query = $caml
    do
        $listItems = $list.GetItems($query)
        $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
        foreach($item in $listItems)
            #Cast to SPListItem to avoid ambiguous overload error
            $spItem = [Microsoft.SharePoint.SPListItem]$item;
            Write-Host $spItem.Title       
    while ($spQuery.ListItemCollectionPosition -ne $null)
    Thanks & Regards
    Poomani Sankaran

  • External data column as shared column in document library with document sets

    Hello,
    I'm using a document library with document sets. Within this document library i have a External data column called "Project"
    This column has it's columns:
    Project: Installatietype
    Project: Relatie
    Project: Object
    Project: Projectleider
    Project: Status_project
    I wan't to use the external data column as an shared column for my document set(s). But i can't figure out or this is possible.

    Hi,
    According to your description, my understanding is that you want to set the external data column as a shared column in document set content type.
    I tested the same scenario in my environment, and the external data column was not supported to be set as a shared column in document set.
    Here is a similar thread for you to take a look:
    http://social.technet.microsoft.com/Forums/en-US/5488b777-1c18-4895-a264-27802b2cde27/document-set-shared-columns-and-bcs-data?forum=sharepointgeneralprevious
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Create document library with 2 columns multitext and lookup.

    Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
    #To which site u want to create the list 
    $spWeb=Get-SPWeb -Identity http://xyz
    #List type or template 
    $spTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary 
    #Get all the lists to the listcollection
    $spListCollection=$spWeb.Lists
    #adding the new list to the list collection
    $spListCollection.Add("Student1","Student1",$spTemplate)
    #get the path of subsite and sitecollecion 
    $path = $spWeb.url.trim()
    #get the list to the list object
    $spList = $spWeb.Lists["Student1"]
    #adding the field type(Note) to the list
    $spFieldType = [Microsoft.SharePoint.SPFieldType]::Note
    $spList.Fields.Add("COMMENTS",$spFieldType,$false)
    $ParentList = $spWeb.Lists.item("Studentlist")
    $spList = $spWeb.Lists["Student1"]
    $spList.Fields.AddLookup("lookupcol",$ParentList.id,$true)
    $spChildListLookupField = $spList.Fields["lookupcol"]
    $spChildListLookupField.LookupField = $ParentList.Fields["ID"]
    $spChildListLookupField.Indexed = $true
    $spChildListLookupField.RelationshipDeleteBehavior = [Microsoft.SharePoint.SPRelationshipDeleteBehavior]::Restrict
    $spChildListLookupField.Update()
    $Views = $spList.Views["All Items"]
    $Views.ViewFields.Add("COMMENTS")
    $Views.ViewFields.Add("lookupcol")
    $Views.Update()
    $spWeb.Dispose()
    I am trying to create a document library with 2 coulmn types multitext and look up but i am getting the following error 
    I am getting erros - You cannot call a method on a null-valued expression - $spList.Fields.Add("COMMENTS",$spFieldType,$false)
    Cannot index into a null array.
    + $spChildListLookupField = $spList.Fields["lookupcol"]
     

    Hi,
    I used the PowerShell you offered to do a test in my SharePoint 2013 and I reproduced your issue. I solved it by doing a little change to the PowerShell which you offered.
    Because you create a document library, the default view of document library is "All Documents" rather than "All Items", just change 
    $Views = $spList.Views["All Items"]
    to
    $Views = $spList.Views["All Documents"]
    Best Regards,
    Lisa Chen
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to connect SharePoint Document Library with Local file system?

    Hi
    I have a SharePoint Document library and in my local system i have 3TB files. It is very difficult to upload 3TB files in SharePoint.
    I want a file details in SharePoint Document Library but physical file would be in local.
    While click the file in Document library. The document should open from local.
    Anyone help me on it.
    Thanks & Regards
    Poomani Sankaran

    Hi,
    your requirement doesn't work out-of-the-box as all data uploaded to SharePoint needs to be stored in SQL database. Thus in your case 3 TB of fileshare would need to move to SQL.
    In case you don't want to go this way, there are 3rd party vendors who offer Software like AvePoint Connector. Products like these use SQL RBS (Storage Externalization API) so that files remain in your file system but metadata is kept in SharePoint. If you
    need more information on that, please let me know.
    Regards,
    Dennis

  • The Create List Item workflow action does not work in document library with document template

    My end goal is more complex but below is a basic example of the issue I’m having that just simply does not work.
    I'm trying to use a site workflow to create an item in a document library that has a document template applied to it but the file that gets created by the workflow is corrupt and cannot be opened.
    I created a document library and edited the document template by adding some text to the header and changing it to a Word docx file instead of a Word dotx file. I tested the document template by clicking the files tab in the ribbon and then clicking new
    document which opens the document template in Word and allows me to edit and save the document back to SharePoint. Then I created a SharePoint 2013 site workflow in SharePoint Designer that contains a single Create List Item action, and that action creates
    an item in the document library with the name field statically defined. I published the workflow and then manually start it on the site. The workflow completes successfully and when I navigate to the document library the document has been created by the workflow.
    When I click on the document to open it in the Word Web App it throws the error pictured below and if I open it in the Word client application it just opens a blank document and not the correct document template.
    I also tried using a SharePoint 2010 workflow with pretty much the same results. Opening the document in Word Web App gives the same error as above and opening the document in the Word client application gives the error pictured below.
    Come on Microsoft creating a Word Document in a SharePoint Document Library from a SharePoint Workflow should just work! Is this a bug or does anyone have any ideas on what is causing the this issue?

    I had the same problem with corrupted document - this worked for me:
    1. Create a 2010 Workflow which creates the list element in a document library
    (you may start this workflow from your 2013 workflow if applicable)
    2. In the Create New List Item properties - make sure to set ContentTypeId to your content type
    ("Id for indholdstype" is Danish for "Contenttype ID")
    3. Your Content Type template should be a ".docx" file - NOT a ".dotx" file...!
    (I have always created my templates for content types as .dotx files - seems Microsoft wants us to use ordinary .docx files as template files for content types)
    Hope this helps you!

  • Using Document Library with Baseline

    Hi there,
    I have a specific need with Sharepoint. I have a document library and I want to be able to mark with a tag or generate a baseline for my folders.
    I've already searched on the web, and there is someone doing it just coping and pasting every single file. Is that the better way to get this?
    Thanks,
    Tiago

    Hi Tiago,
    What did you mean "Using Document Library with Baseline" and "generate a baseline for my folders"?
    Did you mean that navigate the document library folders in treeview?
    Did you mean that search or filter multiple folders documents with the same tag (managed metadata column)?
    You may be able to use the "Navigation Hierarchies and Key Filters" for that specified SharePoint 2010 library, here is an article about metadata navigation settings you can check below,
    http://www.sharepointboost.com/blog/understand-and-configure-metadata-avigation-and-filtering/
    Thanks
    Daniel Yang
    TechNet Community Support

  • Unable to add aspx file to document library using REST and JSOM in SharePoint Hosted App

    Hi,
    I am unable to add an aspx file to document library.  I was actually trying to create a WIKI page and upload to Pages library but that wasn't working so I tried simple document library.  It keeps failing with Access Denied error.  I have checked
    the blocked types and aspx is not included.  I can upload it directly from the browser so that shouldn't be the case.  I have read that it can be achieved with CSOM but I need this to work with a SharePoint Hosted App.  Here is my JSOM:
    factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
        context.set_webRequestExecutorFactory(factory);
        appContextSite = new SP.AppContextSite(context, hostweburl);
        oWeb = appContextSite.get_web();
        oList = oWeb.get_lists().getByTitle('Documents');
        fileCreateInfo = new SP.FileCreationInformation();
        fileCreateInfo.set_url("mywiki.aspx");
        fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
        fileContent = "<%@ Page Inherits=\"Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" %> <%@ Reference VirtualPath=\"~TemplatePageUrl\"
    %> <%@ Reference VirtualPath=\"~masterurl/custom.master\" %>";
        for (var i = 0; i < fileContent.length; i++) {
            fileCreateInfo.get_content().append(fileContent.charCodeAt(i));
        newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);
        context.load(newFile);
        context.executeQueryAsync(function () {
            alert('yo');
        }, function (sender, args) {
            alert(args.get_message() + '\n' + args.get_stackTrace());
    If I change the file extension to "txt", it works.  Same with REST implementation, it works with "txt" but fails with "aspx".  Maybe what I am trying to do will not work using JSOM or REST.  Any suggestions?  Your
    help is always appreciated.
    Regards,
    kashif

    Your code works fine in both my on-premises and SharePoint Online. I have given the app full control, so I suspect this is a permissions issue. I would check your permissions on your appmanifest. Must be something to do with publishing permissions. Try
    giving full control and work the permissions down.
    Blog | SharePoint Field Notes Dev Tools |
    SPFastDeploy | SPRemoteAPIExplorer

  • Download files from document library in zip file using javascript

    Hi,
    I am developing SharePoint Hosted App which needs to download all the files in the document libraries of SharePoint site in a zip folder where in that zip file each document library should be a folder, in that folder the files of that document library will
    be shown. Currently I am display all the document library in a table with check boxes as shown in the below figure. Now when user selects the check boxes and click on download button, the selected document libraries along with the files should be downloaded
    in a zip folder. This should be achieved through javascript. Can anyone share me the code to solve this problem.
    Thanks & Regards,
    Kishore
    Kishore

    You can use
    zip.js, but the best way - implement your solution on the server-side.
    [custom.development]

  • Corrupt document gets created in document library with document template using createlistitem workflowaction in visual studio workflow for office 365 solution

    Hi,
    My requirement is to create a document library associated to a custom content type with a document template associated. Also I need to create a document based on the template in this document library when a new item is created in another list by taking the
    reference ID of that new Item , I need to create the document with the name appended by ID. I need to do all this deployment using WSP.
    I have created document library with document template associated to content type by following instructions in below stated blog :http://blogs.msdn.com/b/chaks/archive/2011/05/19/deploying-a-document-template-file-in-content-type-in-a-office365-sandboxed-solution.aspx
    This works perfect for me.
    However, there are few observations, when going to Document Library > Library Settings > Advanced Settings > Document Template section - doesnt shows the Edit template link. When tried to look at the value for the document template using view source
    , it is giving me /Lists/MyDocsListInstance/Forms/template.dotx instead of the actual template file uploaded.
    Ignoring the above observation, when I am trying to create a sandbox based workflow in visual studio to create document in document library when new item is created in another list, I provide the ContentTypeID as the ID associated with the document library
    with template. 
    It creates the corrupt document at end of workflow. 
    I have tried using .docx instead of .dotx files for workflow as per solution provided in some of the post but it isnt resolving my issue.
    Any help is much appreciated.
    Regards,
    Krutika

    OK, I am going to throw out a lot of ideas here so hopefully they get you closer to a diagnosis. Hang on :)
    Does it happen to work for some users but not others? If so, try logging in on the "good" computer with the "bad" username. This will tell you if the problem is related to the end-user's system. Also, once the user downloads a document
    successfully can they open and work on it in Word? Also, does the document library have any custom content types associated with it or does it just use 'Document'?
    I notice that there are other folks on the web that have run into this same problem and the similarity seems to be that they are either on SharePoint 2007 or have upgraded from 2007. Did this doc library start out as a 2007 library?
    What you might want to do is this: Make a site collection from scratch in 2013 (or find one that you know was created in 2013). Choose team site (or whatever you want) for the root web and set up the security the same way you have it on the malfunctioning
    library. Now, use windows explorer to copy and paste some of the documents to the new location. Be sure you recreate any needed content types. Now test it from the troubled user's computer.
    I'm thinking there may be something that is different about the library since it was migrated through various versions and updates since 2007. I've sometimes found that there can be problems (especially with user profiles but that's a different story) with
    things that go through this evolution.

  • How external users can upload files in document library hosted in onpremise SharePoint?

    Hi all,
    We have setup a document library(DL) in SharePoint site hosed on-premise with no direct access from public zone/internet being an intranet solution. We have some external users who need to upload some files that needs to go in this document
    library. These files are quite confidential in nature so security is a prime requirement. Following are the couple of options I have in mind:
    1. External users upload their file in their designated folder to secure FTP using their own credential set. And also there is a background process (kind of directory watcher) that keep looking at the all the folders
    and moves the files to document library
    2. We host a single page application which has One time password (OTP) kind of feature. External user comes to the secure site to specify Vendor team name and mobile number. OTP is generated and user is asked to specify the password along with file
    they would like to upload. This page also maps the vendor name with respective folder in DL and moves the files to SharePoint there on the fly.
    Pls. share your opinion about these approaches. Also welcome your thoughts if there is any other better option.
    Thanks.

    Hi,
    I agree with the Margriet, the first option is simple and safe, the users could not access the document library directly.
    For security, it is an importance for users not access the document library directly, it will reduce the risk of the documents in the library.
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Jason Guo
    TechNet Community Support

  • Drag and drop the file from document library to desktop in sharepoint 2013

    can we drag and drp the file from document library to desktop in sharepoint 2013
    Blitz

    We are using third party tool called PageLight for
    SharePoint Outlook Integration which provides drag and drop functionality of emails from Outlook to SharePoint.  Other features includes
    Save Outlook emails to SharePoint and also moving files/folders from file share.
    Thanks
    Alfred

  • Is it possible Encrypt files in document library after uploading OOB

    Is it possible Encrypt files in document library after uploading using  OOB?
    if so please share how the above can be achieved.
    V Jean

    hi
    there is no easy OTB mechanism for that. The most closer OTB functionality is Rights Management Services (see
    e.g. Plan Information Rights Management), which seems like can be used for configuring policy for data encryption, like mentioned in the following forum thread:
    How to Encrypt SharePoint data. Also you may use the following methods to make file upload safer:
    1. use https instead of http
    2. use Sharepoint rights system in order to restrict access to the uploaded documents to only allowed persons (e.g. you may use unique permissions on the doclib level or on file level)
    3. if encryption is crucial and you don't want to enable it to all doclibs via RMS, you may use custom solution via event receivers: during file upload it may encypt it by using some standard encryption algorithm (see
    Which built-in .NET cryptography algorithm is the most secure).
    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

Maybe you are looking for