none
Copy document with copy.asmx and set content type

    Frage

  • Hi,

    I'm having alot of problems with my framework by copying a document from one site collection to another and have the content type persist.

    I use webservice copy.asmx and have made a test method for trying to keep content type.

    public static void CopyFile()
        {
          var cSource = new Copy
          {
            Url = "http://intranet/Workspaces/_vti_bin/copy.asmx",
            UseDefaultCredentials = true
          };
    
          FieldInformation[] sourceInfos;
          byte[] sourceBinary;
          var sourceResult = cSource.GetItem("http://intranet/Workspaces/Documents/Nyt dokument.txt", out sourceInfos, out sourceBinary);
          var cDestination = new Copy
          {
            Url = "http://extranet/Test1/_vti_bin/copy.asmx",
            UseDefaultCredentials = true
          };
    
          string[] desUrl = { "http://extranet/Test1/Documents/Nyt dokument.txt" };
          CopyResult[] result;
    
          var sourceInfo = new[]
                   {
                     new FieldInformation { DisplayName = "Title", InternalName = "Title", Type = FieldType.Text, Value = "Min titel!" },
                     new FieldInformation { DisplayName = "Content Type", InternalName = "ContentType", Type = FieldType.Choice, Value = "My Document" },
                   };
          var destinationResult = cDestination.CopyIntoItems("http://extranet/Test1/Documents/Nyt dokument.txt", desUrl, sourceInfo, sourceBinary, out result);
        }

    I have created a content type named "My Document" and also tried to change the FieldType to Text instead of Choice, but nothing works :(

    The example with the content type fieldinformation is functionality i had found on many other blogs but it was to MOSS, and I can't get it to work in SharePoint Server 2010.

    Are there anybody else who have had success with copying a document though copy.asmx and have a content type set in the same process?

     

    Best Regards

    Donnerstag, 11. August 2011 15:21

Antworten

Alle Antworten

  • I wouldn't recommend the webservice, but the Microsoft.SharePoint.Deployment namespace classes...

    SharePoint uses it internally in the manage content and structure page to copy items to another place.
    You can use the SPExport and SPImport classes, these classes allow you to copy items, lists, webs and sitecollections

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.deployment.spexport.aspx

    http://ruudheemskerk.net/archive/2009/05/29/copy-or-move-sharepoint-list-items-using-spexport-and-spimport.aspx


    MCT,MCTS - http://www.tomvangaever.be
    • Als Antwort markiert Shimin Huang Freitag, 19. August 2011 03:24
    Donnerstag, 11. August 2011 18:34
  • Hi Tom,

    Thanks for your feedback. When I started making this functionality I've looked at the SPExport and SPImport, but I didn't find it usefull in my solution because you need to save the files at the local drive, before I need to send the data though webservice and import the data on the extranet farm. I find this approach a kind a difficult to implementent when it's only based on singel files from around the webs.

    I have already make the framework for the customer, så i guess the only solution to solve this problem is to create a custom webservice to handle the file copy.

     

    Freitag, 12. August 2011 05:17
  • This appears to be a bug. In sp2007 the field type was Choice, however, in sp2010 it is actually Computed. I have tried using the Computed field type with no luck. I have also tried sending the ContentTypeId and this does not work.
    Blog | SharePoint Field Notes Dev Tool | ClassMaster
    • Als Antwort markiert Shimin Huang Freitag, 19. August 2011 03:24
    Freitag, 12. August 2011 13:59
  • This is not a bug, just an architecture change in 2010.  In order to set the content type using copy.asmx use the ContentTypeID.  For a SOAP call that would look like:
    <soap: FieldInformation Type="Text" DisplayName="Content Type ID" InternalName="ContentTypeId" Value="yourctypeid" />


    • Bearbeitet jasonkuter Donnerstag, 22. März 2012 18:04
    • Als Antwort vorgeschlagen jasonkuter Montag, 30. April 2012 17:59
    Donnerstag, 22. März 2012 18:04
  • Jason is right , I have created a sample project to use the web service to upload a document with custom content type , you can it here.

    MCPD on Microsoft SharePoint 2010 MCITP: SharePoint Administrator 2010 Enterprise Application Developer 3.5 on Visual Studio 2008 My technical blog : http://ybbest.wordpress.com/

    Samstag, 21. April 2012 10:42