Hi
I am getting above error on below code
MemoryStream ms = new MemoryStream(buffer);
FileStream file = new FileStream(@"D:\" + pdf + ".pdf", FileMode.Create, FileAccess.Write);
ms.WriteTo(file);
file.Close();
ms.Close();
Thanks
Pasang TamangPosted Dec 27, 2022, 7:15 AM
Hi,
You are right. Only the PDF filename part is dynamic I think. For dynamic PDF filename, I would suggest to check your API documentation. I can not tell you how that filename dynamic is handled without knowing your API flow.
Regards,
Pasang
Ramco RamcoPosted Dec 27, 2022, 7:10 AM
Hi Pasanf
I think this part will be fixed .- https://nimubs-assets.s3.amazonaws.com/manifest/
This will be dynamic -20221227113803-73.pdf
Thanks
Pasang TamangPosted Dec 27, 2022, 7:03 AM
Hi,
Dynamic filename depends on your case. May be there is different endpoint that gives you the online file URL.
Regards,
Pasang
Ramco RamcoPosted Dec 27, 2022, 6:57 AM
Hi Pasand
This has to be dynamic - 20221227113803-73.pdf. How i can get this from Api returned content.
It is not fixed.
Thanks
Pasang TamangPosted Dec 27, 2022, 6:48 AM
Hi,
Yes, you can do with RestSharp also. Below is the code example with RestSharp
Regards,
Pasang
Ramco RamcoPosted Dec 27, 2022, 6:37 AM
Hi Pasang
Can't we do thru Rest Sharp
Thanks
Pasang TamangPosted Dec 27, 2022, 6:24 AM
Hi,
You can try with below code also
using (var client = new HttpClient())
{
var pdf = DateTime.Now.ToString("yyyyMMddHHmm");
client.BaseAddress = new Uri("https://nimubs-assets.s3.amazonaws.com");
var content = client.GetByteArrayAsync("/manifest/20221227112426-90.pdf");
MemoryStream ms = new MemoryStream(content.Result);
FileStream file = new FileStream(@"D:\" + pdf + ".pdf", FileMode.Create, FileAccess.Write);
ms.WriteTo(file);
file.Close();
ms.Close();
}
Shervin CyrilPosted Dec 27, 2022, 6:15 AM
we cannot have certain characters in the full PathFile string.
For example, below characters will crash the StreamWriter function
/ , :
Ramco RamcoPosted Dec 27, 2022, 5:56 AM
Hi
Can we do the same thru RestSharp. Below is returned in pdf
https://nimubs-assets.s3.amazonaws.com/manifest/20221227113803-73.pdf
Thanks
Ramco RamcoPosted Dec 27, 2022, 5:55 AM
Hi
Below is returned - https://nimubs-assets.s3.amazonaws.com/manifest/20221227112426-90.pdf
string pdf = json.data;
byte[] buffer = client.DownloadData(request);
MemoryStream ms = new MemoryStream(buffer);
FileStream file = new FileStream(@"D:\" + pdf , FileMode.Create, FileAccess.Write);
Thanks
Ramco RamcoPosted Dec 27, 2022, 5:53 AM
Hi
I am trying below code
Thanks
Shervin CyrilPosted Dec 27, 2022, 5:50 AM
Your code doent generated any error for me.
As @Pasang said , the issue might be in your file name variable - pdf
Pasang TamangPosted Dec 27, 2022, 4:57 AM
Hi Ramco,
It's difficult to point out what problem exactly without having complete code. As I see something must be wrong in your pdf variable which you are using for filename. Below code works with me
Regards,
Pasang