C# 过载错误消息

发布于 2024-11-27 17:25:03 字数 1172 浏览 2 评论 0原文

因此,我一直在尝试使用下面的这段代码来尝试将图像上传到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方的韩爷 2024-12-04 17:25:03

客户端对象模型的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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文