全て
| カテゴリ未分類
| 通常
| 数学
| 投資
| 副業
| 転職・就職
| ブログ
| 株Stock
| VBA
| SharePoint
| REST API
| RenderListDataAsStream
| PowerAutomateDesktop
| Graph API
| PowerApps
| PowerAutomate
| PowerFx
| OfficeScriptオフィススクリプト
| PowerAutomate日時Excel日時相互関係
| PowerShell
| Dataverse
| UiPath
| OneDrive
| LINQ
| VB.NET
| C#.NET
カテゴリ:REST API
using System; using System.IO; using System.Net; using System.Text; namespace SharePointRESTExample { class Program { static void Main(string[] args) { // SharePoint サイトの URL string siteUrl = "https://your-sharepoint-site-url.com"; // リストの名前 string listName = "Documents"; // 新しいフォルダの名前 string folderName = "NewFolder"; // SharePoint サイトのユーザー名とパスワード string username = "your_username"; string password = "your_password"; // フォルダを作成する REST API URL string createFolderUrl = siteUrl + "/_api/web/lists/getByTitle('" + listName + "')/rootfolder/folders"; // SharePoint REST API へのリクエストの準備 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(createFolderUrl); request.Method = "POST"; request.Accept = "application/json;odata=verbose"; request.ContentType = "application/json;odata=verbose"; // ベーシック認証のヘッダーを追加 string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password)); request.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials; // 新しいフォルダのメタデータを作成 string folderMetadata = string.Format("{{ '__metadata': {{ 'type': 'SP.Folder' }}, 'ServerRelativeUrl': '/{0}/{1}' }}", listName, folderName); // 新しいフォルダのメタデータをリクエストに書き込む using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(folderMetadata); streamWriter.Flush(); } try { // REST API からのレスポンスを取得 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // レスポンスの処理 if (response.StatusCode == HttpStatusCode.Created) { Console.WriteLine("Folder created successfully."); } else { Console.WriteLine("Failed to create folder. Status code: " + response.StatusCode); } } catch (WebException ex) { // エラー処理 Console.WriteLine("Error: " + ex.Message); } } } } お気に入りの記事を「いいね!」で応援しよう
Last updated
2024.02.27 07:26:13
[REST API] カテゴリの最新記事
|