2016-11-11 11 views
-1

SharePointリストに画像をアップロードする方法「カスタムリスト」ライブラリなし CSOM C#を使用していますか?csomを使用して共有ポイントに汎用リストをアップロードするC#

FieldUrlValue url = new FieldUrlValue(); 
url.Url = FileUpload.PostedFile.FileName; 
url.Description = "Your description here"; 
newItem["Image"] = url; 
+0

私はエラーが発生しましたupl oadの画像 – zzzz

+0

URL(カスタムリストのフィールドURL)を使用している場合、画像はすでにSharePoint上にある必要があります(また、ローカルコンピュータではなくsharePointからURLを設定してください)。そのため、「URLが無効です」というエラーが表示される – Nico

答えて

0

をあなたはCSOM経由SharePointにドキュメントをアップロードするために、このコードを使用することができます:

using (ClientContext ctx = new ClientContext("http://urlToYourSiteCollection")) { 
    FileCreationInformation fci = new FileCreationInformation(); 
    fci.Content = System.IO.File.ReadAllBytes("PathToSourceDocument"); 
    fci.Url = System.IO.Path.GetFileName("PathToSourceDocument"); 
    Web web = ctx.Web; 
    List targetDocLib = ctx.Web.Lists.GetByTitle("yourTargetLibrary"); 
    ctx.ExecuteQuery(); 
    Microsoft.SharePoint.Client.File newFile = targetDocLib.RootFolder.Files.Add(fci); 
    ctx.Load(newFile); 
    ctx.ExecuteQuery(); 
} 

新しいのプロパティを設定したい場合はここで

は、私がこれまで試してみましたものですあなたはこのようにすることができます:

ListItem lItem = newFile.ListItemAllFields; 
lItem.File.CheckOut(); //CHECK OUT VERY IMPORTANT TO CHANGE PROPS 
ctx.ExecuteQuery(); 
lItem["yourProperty"] = "somewhat"; 
lItem.Update(); 
lItem.File.CheckIn("Z", CheckinType.OverwriteCheckIn); 
ctx.ExecuteQuery(); 
関連する問題