通过SharePoint Web服务模型添加列表项,是否知道如何将附件添加到列表项?
答案 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;
}