excel extension issue

nofu1

Active member
Joined
Oct 30, 2020
Messages
37
Programming Experience
Beginner
I have a code similar to this below

C#Copy

C#:
using(webclient wc = new WebClient())
{
string fileinfoname = "test_one";
string pathinfo = @"C:\testfolderinfo" + fileinfoname + ".xlsx";

wc.downloadFile("www.testurl.com/report", pathinfo);

}
I am currently experiencing a situation where the file is being downloaded but when I try to utilize excel to open the file, it gives the message

"Excel cannot open the file test_one because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file"

This just started happening, hence how do i get an actual excel extension for excel 2007 and above to replace it above.

Thanks in advance
 
Sounds like you need to use something like Postman to see what exactly is being used to create the HTTP request and then replicate that through code. That's the approach I always used and it hasn't failed me yet. Once you have the corret HTTP request and get Postman to download the correct file then you have a blueprint to code from.
 
I usually use Fiddler or the browser DevTools to watch the traffic, then I use PostMan to verify that I can replicate the traffic, and only then move on to using code. The only time I skip the PostMan replication step is if I figure out that there is a very short time to live for any of the response tokens, and I can't do any of the follow-up manually quickly enough.
 
Postman, Insomnia and other rest tools might well generate C# for you (I know insomnia does; i moved away from Postman years ago)

I was looking for an example but I will see what I can create by writing the C# code
 
If it's a soap service it may have a description document that can be used to programmatically generate all the c# you need. Take care not to buy a dog and bark yourself
 
If it's a soap service it may have a description document that can be used to programmatically generate all the c# you need. Take care not to buy a dog and bark yourself

Sorry I don't think I follow or maybe it is due to the fact I have limited knowledge about SOAP, I know a soap is a a combination of XML and a HTTP request, I assumed if one can get the http request and http response working, then the only add-on is the XML envelop which contains all required parameters will be sent as a byte stream in the getrequeststream method but then again i do have limited knowledge
 
Let's step back. Where did you get the URL "https://www.testurl.com/report"? Where did you get the user name and password for logging on to that site? They should have the information about that URL and whether it exposes a SOAP or REST API.
 
Let's step back. Where did you get the URL "https://www.testurl.com/report"? Where did you get the user name and password for logging on to that site? They should have the information about that URL and whether it exposes a SOAP or REST API.


Ok if it has information like this below, how would one approach things, kindly note I am referencing a tutorial I am currently reading on SOAP




Soap request


requestinfo:
POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPrice>
    <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>

</soap:Envelope>

soap response

responseinfo:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPriceResponse>
    <m:Price>34.5</m:Price>
  </m:GetStockPriceResponse>
</soap:Body>

</soap:Envelope>
 
This seems to be an exercise in misdirection; that SOAP request appears to be an example from the w3schools tutorial. It is definitely not a SOAP dialogue that involves the requesting and receipt of an excel binary file

We're trying to help you with the actual problem you're having, so that means you need to post details about it specifically.. not paste in things completely unrelated to it
 
Back
Top Bottom