2015-07-06 1 views
2

У меня есть требование загрузить файлы в sharepoint с помощью sharepoint webservices. Существуют ли какие-либо службы sharepoint, которые потребляют содержимое файла в качестве данных base64 внутри запроса на мыло?Любой способ загрузить файл в sharepoint через webservice

+0

[Загрузка контента в SharePoint] (http://sharepointfieldnotes.blogspot.in/2009/09/uploading-content-into-sharepoint-let.html) – Naveen

ответ

1

Я искал простой запрос на мыло, который может выполнить эту работу, и с помощью комментариев от @ElvisLikeBear я смог использовать веб-службу CopyIntoItems в http://server/sites/personal/_vti_bin/copy.asmx.

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP:Body> 
    <CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"> 
     <SourceUrl>fileName.ext</SourceUrl> 
     <DestinationUrls> 
     <string>{your share point location to where the file has to be uploaded.}http://mySharepoint/mysharepointsite/fileName.ext</string> 
     </DestinationUrls> 
     <Fields> 
     <!--FieldInformation Type="Note" DisplayName="CustomerMeta_0" InternalName="" Id="12345678-4564-9875-1236-326598745623" Value="xxx" /--> 
     </Fields> 
     <Stream>Base 64 encoded content </Stream> 
    </CopyIntoItems> 
    </SOAP:Body> 
</SOAP:Envelope> 
+0

FieldInformation тег несет метаданные, его не обязательно –

2

This ресурс поможет вам понять это.

Вот соответствующий контент из статьи в случае, если связь нарушается для будущих читателей:

Давайте Загрузить документ

Чтобы загрузить документ, нам нужно добавить еще одну ссылку на службу к http://server/sites/personal/_vti_bin/copy.asmx. Это служба копирования .

Вот код, чтобы загрузить документ в библиотеке документов:

CopySoapClient client = new CopySoapClient(); 

if (client.ClientCredentials != null) 
{ 
    client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; 
} 

try 
{ 
    client.Open(); 
    string url = "http://server/sites/personal/My Documents Library/Folder One/Folder Two/"; 
    string fileName = "test.txt"; 
    string[] destinationUrl = { url + fileName }; 
    byte[] content = new byte[] { 1, 2, 3, 4 }; 

    // Description Information Field 
    FieldInformation descInfo = new FieldInformation 
            { 
             DisplayName = "Description", 
             Type = FieldType.Text, 
             Value = "Test file for upload" 
            }; 

    FieldInformation[] fileInfoArray = { descInfo }; 

    CopyResult[] arrayOfResults; 

    uint result = client.CopyIntoItems(fileName, destinationUrl, fileInfoArray, content, out arrayOfResults); 
    Trace.WriteLine("Upload Result: " + result); 

    // Check for Errors 
    foreach (CopyResult copyResult in arrayOfResults) 
    { 
     string msg = "====================================" + 
         "SharePoint Error:" + 
         "\nUrl: " + copyResult.DestinationUrl + 
         "\nError Code: " + copyResult.ErrorCode + 
         "\nMessage: " + copyResult.ErrorMessage + 
         "===================================="; 

     Trace.WriteLine(msg); 
     _logFactory.ErrorMsg(msg); 
    } 
} 
finally 
{ 
    if (client.State == CommunicationState.Faulted) 
    { 
     client.Abort(); 
    } 

    if (client.State != CommunicationState.Closed) 
    { 
     client.Close(); 
    } 
} 
2

Вы можете использовать Spservises для достижения требуемой функциональности. Пожалуйста, смотрите код ниже:

function UploadFile(listName,itemId,files){ 
    var filereader = {}, 
     file = {}; 
    var fileLength = files.length; 
    //loop over each file selected 
    for(var i = 0; i < files.length; i++) 
    { 
     file = files[i];    
     filereader = new FileReader();   
     filereader.filename = file.name; 
     filereader.onload = function() {     
      var data = this.result,      
       n=data.indexOf(";base64,") + 8;    
      //removing the first part of the dataurl give us the base64 bytes we need to feed to sharepoint 
      data= data.substring(n); 
      $().SPServices({ 
       operation: "AddAttachment",     
       listName: listName, 
       asynch: true, 
       listItemID:itemId, 
       fileName: this.filename, 
       attachment: data, 
       completefunc: testFunction(i,fileLength) 
          });     
     }; 
     filereader.onabort = function() { 
      alert("The upload was aborted."); 
     }; 

     filereader.onerror = function() { 
      alert("An error occured while reading the file."); 
     };    

     //fire the onload function giving it the dataurl 
     filereader.readAsDataURL(file); 

    } 

Здесь files есть файлы, возвращаемые с помощью элемента управления HTML-файла для загрузки.

 Смежные вопросы

  • Нет связанных вопросов^_^