SharePoint通过Web服务:如何添加附件?

时间:2009-10-02 08:22:59

标签: sharepoint sharepoint-2007 wss

通过SharePoint Web服务模型添加列表项,是否知道如何将附件添加到列表项?

1 个答案:

答案 0 :(得分:4)

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

safeFileName function =

 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; 
        }