【发布时间】:2011-08-04 17:01:56
【问题描述】:
所以我一直在尝试使用下面的这段代码来尝试将图像上传到 SharePoint 图像库。
static NetworkCredential credentials = new NetworkCredential(username, password, domain);
static ClientContext clientContext = new ClientContext(siteURL);
static Web site = clientContext.Web;
static List list = site.Lists.GetByTitle("Site Images");
private static byte[] StreamFile(string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
// Create a byte array of file stream length
byte[] ImageData = new byte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();
return ImageData;
}
private static void uploadImage()
{
String fileName = "Sunset";
String filePath = "C://Documents and Settings//Desktop//Sample Extracted Pic.jpeg";
list.RootFolder.Files.Add(fileName, StreamFile(filePath));
}
...一切似乎都很好(至少在编译器中),直到您到达:list.RootFolder.Files.Add(fileName, StreamFile(fileName));
编译器返回一个错误说No overload for method 'Add' takes 2 arguments,我明白它在说什么,但我不知道为什么我会收到这个错误。有没有人有任何想法或建议的解决方案?感谢所有反馈。
【问题讨论】:
-
假设它是
SPList,这应该可以。根据此页面msdn.microsoft.com/en-us/library/ms461726.aspx,有一个带有 2 个参数、一个字符串和一个字节数组的重载。你确定这是错误所在吗? -
抱歉,这是问题所在,不是输入
SPLIST。此时我无法访问服务器上的目录以使用 microsoft.sharepoint.dll 文件。因此,我试图找到另一种方法。我在原始代码中包含了一些额外的变量。 -
您的目标服务器是哪个版本? WSS 3.0 还是 SP 2010?您是使用客户端 SDK 还是直接使用其中一种 Web 服务(例如 Lists.asmx)?
标签: c# sharepoint new-operator overloading arguments