示例#1
0
 /// <summary>
 /// Get information about folder
 /// </summary>
 /// <param name="folder_id"></param>
 /// <returns></returns>
 public FolderInfo AboutFolder(string folder_id)
 {
     FolderInfo fi = new FolderInfo();
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(" https://api.box.com/2.0/folders/" + folder_id);
     request.Method = "GET";
     request.Headers.Add("Authorization", "BoxAuth api_key=" + api_key + "&auth_token=" + auth_token);
     StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream());
     string response = reader.ReadToEnd();
     try
     {
         //shared with items
         fi = JsonConvert.DeserializeObject<FolderInfo>(response);
     }
     catch (System.Exception)
     {
         try
         {
             //items
             fi = ConvetrFolderInfo(JsonConvert.DeserializeObject<FolderInfoItems>(response));
         }
         catch (System.Exception)
         {
             try
             {
                 //shared
                 fi = ConvetrFolderInfo(JsonConvert.DeserializeObject<SharedFolderInfo>(response));
             }
             catch (System.Exception)
             {
                 //empty
                 fi = ConvetrFolderInfo(JsonConvert.DeserializeObject<CreateFolderInfo>(response));
             }
         }
     }
     return fi;
 }
示例#2
0
 /// <summary>
 /// Update folder information
 /// Serialization
 /// </summary>
 /// <param name="folder_info"></param>
 public void UpdateFolderInfo(FolderInfo folder_info)
 {
 }
示例#3
0
 /// <summary>
 /// Convert SharedFolderInfo object to FolderInfo object
 /// </summary>
 /// <param name="shi"></param>
 /// <returns></returns>
 private FolderInfo ConvetrFolderInfo(SharedFolderInfo shi)
 {
     FolderInfo fi = new FolderInfo();
     fi.create_by = shi.created_by;
     fi.created_at = shi.created_at;
     fi.description = shi.description;
     fi.id = shi.id;
     fi.item_collection = null;
     fi.modified_at = shi.modified_at;
     fi.modified_by = shi.modified_by;
     fi.name = shi.name;
     fi.owned_by = shi.owned_by;
     fi.parent = shi.parent;
     fi.sequence_id = fi.sequence_id;
     fi.shared_link = shi.shared_link;
     fi.size = shi.size;
     fi.type = shi.type;
     return fi;
 }
示例#4
0
 /// <summary>
 /// Shared folder
 /// </summary>
 /// <param name="folder_id"></param>
 /// <param name="access"></param>
 /// <param name="download"></param>
 /// <param name="preciew"></param>
 /// <returns></returns>
 public FolderInfo ShareFolder(string folder_id, string access, bool download, bool preciew)
 {
     FolderInfo fi = new FolderInfo();
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(" https://api.box.com/2.0/folders/" + folder_id);
     request.Method = "PUT";
     request.Headers.Add("Authorization", "BoxAuth api_key=" + api_key + "&auth_token=" + auth_token);
     string xml_request = "{\"shared_link\": {\"access\": \"open\"}}";
     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());
     string response = reader.ReadToEnd();
     try
     {
         //shared with items
         fi = JsonConvert.DeserializeObject<FolderInfo>(response);
     }
     catch (System.Exception)
     {
         try
         {
             //items
             fi = ConvetrFolderInfo(JsonConvert.DeserializeObject<FolderInfoItems>(response));
         }
         catch (System.Exception)
         {
             try
             {
                 //shared
                 fi = ConvetrFolderInfo(JsonConvert.DeserializeObject<SharedFolderInfo>(response));
             }
             catch (System.Exception)
             {
                 //empty
                 fi = ConvetrFolderInfo(JsonConvert.DeserializeObject<CreateFolderInfo>(response));
             }
         }
     }
     return fi;
 }