0
所以我一直試圖使用下面的這段代碼來嘗試上傳一個圖像到SharePoint圖像庫。C#重載錯誤消息
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
,我明白它的說法,但我有不知道爲什麼我得到這個錯誤。有沒有人有任何想法或建議的解決方案?所有的反饋意見。
什麼類型是'list'? –
假設它是一個'SPList',這應該起作用。根據該頁面http://msdn.microsoft.com/en-us/library/ms461726.aspx,存在過載服用2個參數,一個串和一個字節數組。你確定這是錯誤的地方嗎? –
對不起,這是問題,它不是'SPLIST'類型。此時我無法訪問服務器上的目錄以使用microsoft.sharepoint.dll文件。因此,我試圖找到一種替代方法。 我在我的原始代碼中包含了一些額外的變量。 –