0

I have to download some files from a server which has 2 stage authentication for a PowerPoint Addin I am trying to develop.

First, I log into the workspace through a browser...

In that browser I can call a .txt file and the contents are displayed in the browser - Great!

In my PowerPoint Addin I then have the following code for download a PP file and open it...

Globals.ThisAddIn.Application.Presentations.Open(@"https://workspace2.blahblah.com/group/corenarratives/Shared%20Documents/corenarratives/BlankPresentationTemplate.pptx");

This downloads the pptx file and opens it perfect! - Great!

I then try and download a .txt file with this code:

WebClient wc = new WebClient();
wc.DownloadFile("https://workspace2.blahblah.com/group/corenarratives/Shared%20Documents/corenarratives/rts.txt", @"C:\trev\trev.txt");

And the contents of the file contains a html error page...

When I save the .txt file as a .html file and open it in a browser it redirects me to the workspace login page...

I don't understand why the PowerPoint file opens and the .txt file doesn't?

And, how, if possible, to download the .txt file?

Can anyone help please?

Thanks

Trevor Daniel
  • 3,785
  • 12
  • 53
  • 89

1 Answers1

0

Is it ok to post an answer I would describe as "in progress"?

I know I guy on twitter who really knows his stuff.

Not a close friend but someone who I had followed for a long time. he wrote fiddler.

So, I stuck my neck out and asked him.

This is what he said.

"Watch your traffic from each scenario with Fiddler. Is PPT sending a Cookie, Auth header, or User-Agent your code needs to send?"

"WebClient isn't based on WinINET/URLMon. PowerPoint downloads (often) are, and that means it gets cookies, UA string, etc."

"PowerPoint has cookies and automatic authentication behaviors inherited from URLMon/WinINET."

Which, if I understand correctly, explains why PowerPoint can download a file..

I think.

Update:

I ended up implement this:

Is it possible to transfer authentication from Webbrowser to WebRequest

HTH

Community
  • 1
  • 1
Trevor Daniel
  • 3,785
  • 12
  • 53
  • 89