2009-10-02 100 views
1

通過SharePoint Web服務模型添加列表項,任何想法如何將附件添加到列表項?通過網絡服務的SharePoint:如何添加附件?

+0

感謝您將這些問題和答案到系統中。你可以用'sharepoint'來標記你的問題嗎? Web服務適用於WSS 3.0和SharePoint 2007.謝謝! – 2009-10-02 13:50:34

+0

亞歷克斯重申了這一點,將來會正確標記他們。 – 2009-10-05 10:08:08

回答

4
wsLists.AddAttachment(this.ListName, listItemID, safeFileName(attachment.Name), File.ReadAllBytes(attachment.FullName)); 

safeFileName功能=

private string safeFileName(string filename) 
     { 
      filename = filename.Replace(@"\", ""); 
      filename = filename.Replace(@"/", ""); 
      filename = filename.Replace(@":", ""); 
      filename = filename.Replace(@"*", ""); 
      filename = filename.Replace(@"?", ""); 
      filename = filename.Replace(@"""", ""); 
      filename = filename.Replace(@"<", ""); 
      filename = filename.Replace(@">", ""); 
      filename = filename.Replace(@"|", ""); 
      filename = filename.Replace(@"#", ""); 
      filename = filename.Replace(@"{", ""); 
      filename = filename.Replace(@"}", ""); 
      filename = filename.Replace(@"%", ""); 
      filename = filename.Replace(@"~", ""); 
      filename = filename.Replace(@"&", ""); 
      return filename; 
     } 
+0

啊,太棒了。感謝安全的文件名功能。我必須在下週實施這件事。 – Chrisb 2009-10-03 04:05:16