/// <summary> /// Convert CreateFolderInfo object to FolderInfo object /// </summary> /// <param name="cfi">CreateFolderInfo object</param> /// <returns>FolderInfo object</returns> private FolderInfo ConvetrFolderInfo(CreateFolderInfo cfi) { FolderInfo fi = new FolderInfo(); fi.create_by = cfi.created_by; fi.created_at = cfi.created_at; fi.description = cfi.description; fi.id = cfi.id; fi.item_collection = null; fi.modified_at = cfi.modified_at; fi.modified_by = cfi.modified_by; fi.name = cfi.name; fi.owned_by = cfi.owned_by; fi.parent = cfi.parent; fi.sequence_id = cfi.sequence_id; fi.shared_link = null; fi.size = cfi.size; fi.type = cfi.type; return fi; }
/// <summary> /// The new folder will be created inside of the parent folder /// </summary> /// <param name="parent_id">Id of parent folder</param> /// <param name="foldername">Name of new folder</param> /// <param name="isshared">Is folder shared</param> /// <returns name="FolderInfo">Information about created file</returns> public FolderInfo CreateFolder(string parent_id, string foldername, bool isshared) { CreateFolderInfo cfi = new CreateFolderInfo(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(" https://api.box.com/2.0/folders/" + parent_id); request.Method = "POST"; request.Headers.Add("Authorization", "BoxAuth api_key=" + api_key + "&auth_token=" + auth_token); string xml_request = "{\"name\":\"" + foldername + "\"}"; byte[] byteData = UTF8Encoding.UTF8.GetBytes(xml_request); request.ContentLength = byteData.Length; using (Stream postStream = request.GetRequestStream()) { postStream.Write(byteData, 0, byteData.Length); } StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()); cfi = JsonConvert.DeserializeObject<CreateFolderInfo>(reader.ReadToEnd()); return ConvetrFolderInfo(cfi); }