C# 过载错误消息
因此,我一直在尝试使用下面的这段代码来尝试将图像上传到 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));
编译器返回一个错误,指出 < code>“Add”方法没有重载需要 2 个参数,我明白它的意思,但我不知道为什么会收到该错误。有人有任何想法或建议的解决方案吗?感谢所有反馈。
So I've been trying to use this piece of code below to try and upload an image into the SharePoint image library.
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));
}
...And everything seems fine (at least within the compiler), until you get to: list.RootFolder.Files.Add(fileName, StreamFile(fileName));
The compiler returns an error saying No overload for method 'Add' takes 2 arguments
, and I understand what it's saying, but I have no idea why I am getting that error. Does anyone have any idea or proposed solutions? All feedback is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
客户端对象模型的Add方法只有一个参数:FileCreationInformation。有关更多详细信息,请参阅此 MSDN 页面:http:// /msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.filecollection.add.aspx
The client object model's Add method only has one parameter: FileCreationInformation. See this MSDN page for more details: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.filecollection.add.aspx