Click here to Skip to main content
14,981,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo everybody,

I added a folder to a system through an API call, now I also have to add a file to this folder.
C#
class Program
    {
        static void Main(string[] args)
        {
            var client = new RestClient("http://172.18.xxxxxx");
            client.Authenticator = new HttpBasicAuthenticator("xxxxxxxxxxxxx", "xxxx");
            client.Timeout = -1;
            var request = new RestRequest("/osrest/api/documents/insert", Method.POST);
            request.AddHeader("content-type", "multipart/form-data");
            request.AlwaysMultipartFormData = true;


            request.AddParameter("Object", "{\"cabinet\": \"Posteingang\",\"name\": \"Posteingang\",\"objectTypeId\":" + " \"2\",\"fields\": {\"Eingangsdatum\": {\"value\": \"21.12.2020\"}}}");

            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);

therefor there are in restsharp:
C#
request.AddFile

Now I have to call up a file in the folder that was created by the previous API call again and the second call through
C#
request.AddFile("file", fileStream, filename);

insert the file in the folder?

or is it enough just one call?

Thanks for answers

What I have tried:

C#
class Program
    {
        static void Main(string[] args)
        {
            var client = new RestClient("http://172.18.24.169");
            client.Authenticator = new HttpBasicAuthenticator("Administrator", "Smart2019");
            client.Timeout = -1;
            var request = new RestRequest("/osrest/api/documents/insert", Method.POST);
            request.AddHeader("content-type", "multipart/form-data");
            request.AlwaysMultipartFormData = true;

           
            request.AddParameter("Object", "{\"cabinet\": \"Posteingang\",\"name\": \"Posteingang\",\"objectTypeId\":" + " \"2\",\"fields\": {\"Eingangsdatum\": {\"value\": \"21.12.2020\"}}}");
      


            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            _ = new RestClient("http://172.18.24.169");
            client.Authenticator = new HttpBasicAuthenticator("Administrator", "Smart2019");
            client.Timeout = -1;
            _ = new RestRequest("/osrest/api/documents/insert", Method.POST);
            request.AddHeader("content-type", "multipart/form-data");
            request.AlwaysMultipartFormData = true;
           }  
   }
Posted
Updated 22-Dec-20 3:47am
v3
Comments
Gerry Schmitz 22-Dec-20 9:59am
   
Your tone implies it works and you're asking for our approval. It's not up to us; we generally just try to fix stuff that is broken.
MMazi 22-Dec-20 10:01am
   
I understand, but mine is broken and not working properly
Dave Kreskowiak 22-Dec-20 11:02am
   
"Not working" is the most useless problem description. Explain the problems in more detail. Any error messages? What DOES happen? What does NOT happen? What exactly is expected?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900