Click here to Skip to main content
14,832,467 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to save DataGridView cell and text color? Pin
OriginalGriff7-Jan-21 7:49
mveOriginalGriff7-Jan-21 7:49 
GeneralRe: How to save DataGridView cell and text color? Pin
Alex Dunlop7-Jan-21 7:52
MemberAlex Dunlop7-Jan-21 7:52 
GeneralRe: How to save DataGridView cell and text color? Pin
OriginalGriff7-Jan-21 8:22
mveOriginalGriff7-Jan-21 8:22 
GeneralRe: How to save DataGridView cell and text color? Pin
Alex Dunlop12-Jan-21 5:58
MemberAlex Dunlop12-Jan-21 5:58 
Questionretrieve the date selected on a calendar control scheduler in C # Pin
Member 150371265-Jan-21 4:14
MemberMember 150371265-Jan-21 4:14 
AnswerRe: retrieve the date selected on a calendar control scheduler in C # Pin
OriginalGriff5-Jan-21 6:44
mveOriginalGriff5-Jan-21 6:44 
AnswerRe: retrieve the date selected on a calendar control scheduler in C # Pin
Ralf Meier6-Jan-21 22:31
professionalRalf Meier6-Jan-21 22:31 
QuestionSending Multiple Files in a single Request to API Pin
brown715764-Jan-21 6:49
Memberbrown715764-Jan-21 6:49 
I am fairly new to API's. I am writing a "simple" API that will convert .docx files to .pdf files and return the pdf's back to the client for saving. I have the code working for a single file but I wanted to code the API to handle multiple files in a single request. Now the API is not receiving the request. I can provide the working code with a single file if requested.

I am sure I am missing something simple. Please see below and see if anyone see's something that I could be doing better or why the API is not receiving the POST request.

Client:
List<string> documents = new List<string>();

private async void btnConvert_Click(object sender, EventArgs e)
{
    using (var client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }))
    {
        client.BaseAddress = new Uri(BaseApiUrl);
        //client.DefaultRequestHeaders.Add("Accept", "application/json");

        // Add an Accept header for JSON format.
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, BaseApiUrl + ApiUrl);

        foreach (string s in docPaths)
        {
            byte[] bte;
            bte = File.ReadAllBytes(docPath);

            string data = JsonConvert.SerializeObject(Convert.ToBase64String(bte));
            documents.Add(data);
        }

        using (var formData = new MultipartFormDataContent())
        {
            foreach (string s in documents)
            {
                //add content to form data
                formData.Add(new StringContent(s, Encoding.UTF8, "application/json"));
            }

            // List of Http Reponse Messages
            var conversions = documents.Select(doc => client.PostAsync(BaseApiUrl + ApiUrl, formData)).ToList();

            //Wait for all the requests to finish
            await Task.WhenAll(conversions);

            //Get the responses
            var responses = conversions.Select
                (
                    task => task.Result
                );

            foreach (var r in responses)
            {
                // Extract the message body
                var s = await r.Content.ReadAsStringAsync();
                SimpleResponse res = JsonConvert.DeserializeObject<SimpleResponse>(s);

                if (res.Success)
                {
                    byte[] pdf = Convert.FromBase64String(res.Result.ToString());

                    // Save the PDF here
                }
                else
                {
                   // Log issue
                }
            }
        }
    }


API: This is function that should get the request from the client but it's not being hit.

[HttpPost]
public async Task<List<SimpleResponse>> Post([FromBody]string request)
{
    var response = new List<SimpleResponse>();
    AIMSConverter convert = new AIMSConverter();

    var provider = new MultipartMemoryStreamProvider();
    await Request.Content.ReadAsMultipartAsync(provider);
    foreach (var requestContents in provider.Contents)
    {
        try
        {
            //var result = convert.CovertDocToPDF(requestContents, WebConfigurationManager.AppSettings["tempDocPath"], WebConfigurationManager.AppSettings["tempPdfPath"]);

            //response.Add(new SimpleResponse() { Result = result, Success = true });
        }
        catch (Exception ex)
        {
            response.Add(new SimpleResponse() { Success = false, Exception = ex, Errors = new List<string>() { string.Format("{0}, {1}", ex.Message, ex.InnerException?.Message ?? "") } });
        }
    }

    return response;
}


SimpleResponse Model:

public class SimpleResponse
{
    public object Result { get; set; }
    public bool Success { get; set; }
    public Exception Exception { get; set; }
    public List<string> Errors { get; set; }
}

AnswerRe: Sending Multiple Files in a single Request to API Pin
Richard Deeming4-Jan-21 22:19
mveRichard Deeming4-Jan-21 22:19 
Questioncode C# pour recuperer la date correspondante lorsqu'on clique sur une cellule Pin
Member 150371264-Jan-21 6:25
MemberMember 150371264-Jan-21 6:25 
AnswerRe: code C# pour recuperer la date correspondante lorsqu'on clique sur une cellule Pin
Dave Kreskowiak4-Jan-21 6:37
mveDave Kreskowiak4-Jan-21 6:37 
AnswerRe: code C# pour recuperer la date correspondante lorsqu'on clique sur une cellule Pin
OriginalGriff4-Jan-21 8:28
mveOriginalGriff4-Jan-21 8:28 
QuestionWhat is the way to connect and stream IP camera Pin
Member 133273664-Jan-21 0:28
MemberMember 133273664-Jan-21 0:28 
AnswerRe: What is the way to connect and stream IP camera Pin
Richard MacCutchan4-Jan-21 0:31
mveRichard MacCutchan4-Jan-21 0:31 
GeneralRe: What is the way to connect and stream IP camera Pin
Member 133273664-Jan-21 0:56
MemberMember 133273664-Jan-21 0:56 
AnswerRe: What is the way to connect and stream IP camera Pin
OriginalGriff4-Jan-21 0:31
mveOriginalGriff4-Jan-21 0:31 
GeneralRe: What is the way to connect and stream IP camera Pin
Member 133273664-Jan-21 0:58
MemberMember 133273664-Jan-21 0:58 
AnswerRe: What is the way to connect and stream IP camera Pin
RickZeeland4-Jan-21 0:40
mveRickZeeland4-Jan-21 0:40 
QuestionUsing 4D linked List make a Full functional Noted Pad on Winform Pin
Member 150308153-Jan-21 12:39
MemberMember 150308153-Jan-21 12:39 
AnswerRe: Using 4D linked List make a Full functional Noted Pad on Winform Pin
OriginalGriff3-Jan-21 20:22
mveOriginalGriff3-Jan-21 20:22 
GeneralRe: Using 4D linked List make a Full functional Noted Pad on Winform Pin
Member 150308154-Jan-21 4:37
MemberMember 150308154-Jan-21 4:37 
GeneralRe: Using 4D linked List make a Full functional Noted Pad on Winform Pin
Mycroft Holmes4-Jan-21 11:26
professionalMycroft Holmes4-Jan-21 11:26 
QuestionHow to make DataGridView scrolling smooth (flickers problem)? Pin
Alex Dunlop3-Jan-21 6:15
MemberAlex Dunlop3-Jan-21 6:15 
AnswerRe: How to make DataGridView scrolling smooth (flickers problem)? Pin
Maciej Los3-Jan-21 23:47
mveMaciej Los3-Jan-21 23:47 
GeneralRe: How to make DataGridView scrolling smooth (flickers problem)? Pin
Alex Dunlop4-Jan-21 5:46
MemberAlex Dunlop4-Jan-21 5:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.