upload a document to SharePoint library, but document uploaded the name's is "noname"

  • 12 August 2014
  • 2 replies
  • 0 views

Badge +3

Dears, 

 

I used a SmartObject WCF service to create a document in a  SharePoint library, but each time I uploaded the document I found that the uploaded document's name is "noname".

So can any one help with some code to upload a document using SO to SP library?

 

This is my code

 

// fullPath is the path to the document which is needed to upload

// attachment is the SO

// aClient is SO client 

 

using (FileStream reader = new FileStream(fullPath, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
attachment.Title = "mail.msg";
attachment.File_K2_ServiceDefined = Convert.ToBase64String(buffer);
}

aClient.AttachmentsSvc_Create(attachment); 

 

 

Thank you, 

Mostafa.


2 replies

Badge +3

Dears, 

I've solved this, it should be

 

// fullPath is the path to the document which is needed to upload

// attachment is the SO

// aClient is SO client 

 

using (FileStream reader = new FileStream(fullPath, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
attachment.Title = "mail.msg";
 attachment.File_K2_ServiceDefined = "<file><name>mail.msg</name><content>" + Convert.ToBase64String(buffer) + "</content></file>";
}

aClient.AttachmentsSvc_Create(attachment); 

Badge +4

Thanks for keeping us up to date :)

Reply