How to upload file in Content Server (OTCS) using REST API and C#

static string createDocument(string authToken, string type, string parent_id, string name, string description, string file)

    {

            var client = new RestClient("http://localhost/otcs/cs.exe/");

      var request = new RestRequest("api/v1/nodes", Method.POST);

      request.AddHeader("OTCSTICKET", authToken);

       

      request.AddParameter("type", type);

      request.AddParameter("parent_id", parent_id);

      request.AddParameter("name", name);

      request.AddParameter("description", description);

      request.AddFile("file", file);

       

      var content = JObject.Parse(client.Execute(request).Content);

      return content["id"].ToString();

    }

Comments

  • Hi All,

    Found Solution !!! :D

    I am able to upload a file using below code in C#.

    C# Code:

    static string createDocument(string authToken, string type, string parent_id, string name, string description, string file)

        {

          var client = new RestClient("http://localhost/otcs/cs.exe/");

          var request = new RestRequest("api/v1/nodes", Method.POST);

          request.AddHeader("OTCSTICKET", authToken);

          request.AddParameter("type", type);

          request.AddParameter("parent_id", parent_id);

          request.AddParameter("name", name);

          request.AddParameter("description", description);

          request.AddFile("file", file);

          var content = JObject.Parse(client.Execute(request).Content);

          return content.ToString();

        }

    Moreover while calling the method we need to provide complete path of a file in given format. Below is the sample request.

    createDocument(authToken, "144", "2000", "File1", "File1", "C:\\Users\\Administrator\\Desktop\\Sample Document.txt")