十岁的初学者,您需要在此处更改一些硬编码设置
public void addToSharepointImageList(string folderName, string fileName, byte[] content)
{
string path = @"\\yoursite\yourlistname\";
string baseSharePointPath = "http://yoursite/";
string listName = "yourlistname";
SharePointImagingService.Imaging svc = null;
try
{
path += folderName;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
#region create sharepoint service
svc = new SharePointImagingService.Imaging();
NetworkCredential nc = new NetworkCredential("username", "password", "domain");
svc.Credentials = nc;
//svc.Credentials = System.Net.CredentialCache.DefaultCredentials;
svc.Url = baseSharePointPath + listName+ "/_vti_bin/imaging.asmx";
svc.Discover();
#endregion
svc.Upload(baseSharePointPath + listName, folderName, content, fileName, true);
}
catch (Exception e)
{
//deal with error
}
finally
{
svc.Dispose();
}
}
或者,如果您尝试将文件直接保存到非图像列表中,您可以将 sharepoint 视为一个巨大的文件共享,然后打开一个文件流并在那里写入字节数组。