0

I'm currently developing a VB.NET application at work to optimize and kind of automate the work process.

Part of the job is downloading a .pdf file from our intranet. For this, we open the IE with a script and CPAU.exe (script below)
Then we fill a form with a "ITEM" number and download the pdf.
The intranet site then runs JavaScript to get the file.

Currently, I am doing this by opening a new IE task with the CPAU script, filling the form with Document.GetElementByName, clicking on the download link and open the file with FindWindowEx. But this way, is not very reliable and might be confusing for users because the IE window is visible for 1-2sec. and then downloading the file while not visible etc.

Now for my application, I want to implement the JavaScript and directly download/open the .pdf file.

Is this possible or might there be another way to achieve this?
Maybe with WebBrowser.InvokeScript Method ?

INFO:
The name of the element to fill in the "ITEM" number:

ctl00$ContentPlaceHolderTitle$tbNumber

Button for searching the file:

ctl00$ContentPlaceHolderTitle$btnFind

Download link if file is found(ID):

ctl00_ContentPlaceHolderMain_tabQueries_TabPanel1_repeaterSearchResults_ctl01_lbRevision1

HTML Code Intranetsite:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="ctl00_Head1">
<link href="css/style.css" rel="Stylesheet" type="text/css" /><link href="/DataExchange/WebResource.axd?d=oqKxFu2-Kkwmw84aF_jPsbV8vFkmrbO8RmdO-H9m1LRPwhTvrLG5TvYvmWJy59oLT5QxSY88zL2KfuVPFlCGLO0TDMUof8iBU9lF5bgeBtjL6fOev_rt0sskhZ9XbiCAQ7WJoSkJRjknXjWqGADHyQ2&amp;t=635719611620000000" type="text/css" rel="stylesheet" /><title>
 Data Exchange V3.0.1.18
</title></head>
<body>
    <form name="aspnetForm" method="post" action="./" id="aspnetForm">
<div>
<input type="hidden" name="ctl00_ScriptManager_HiddenField" id="ctl00_ScriptManager_HiddenField" value="" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="ctl00_ContentPlaceHolderMain_tabQueries_ClientState" id="ctl00_ContentPlaceHolderMain_tabQueries_ClientState" value="{&quot;ActiveTabIndex&quot;:0,&quot;TabState&quot;:[true,true,true,true]}" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMTQxMTkyMDk0D2QWAmYPZBYCAgEPZBYGAgMPDxYCHgRUZXh0BRNIdXNreSBEYXRhIEV4Y2hhbmdlZGQCBQ9kFgICAQ9kFgJmD2QWGAIBDw8WAh8ABQdJdGVtICM6ZGQCBQ8PFgIeB1Zpc2libGVoZGQCBw8PFgIfAWhkZAILDxAPFgIfAWdkZGRkAg0PEA8WAh8BaGRkZGQCEQ8PFgIfAAUDMjQwZGQCFQ8PFgIfAAUDQWxsZGQCFw8QZBAVFQAEQk8xVgJIQghtYXJrdXAxVghNQzE1MTNWMghNQzE1MTNWMwhNQzE1MTNWNAVNQ0QzVgVNQ0Q0VgVNQ0Q1VghNQ0QxODE2VglNQ0QyMDE4VjEGTUxSVDJWBk1MUlQzVgZNTFJUNFYFTU1DMlYET1IyVgRPUjNWBVY1NVYxBVlBUzFWBVlBUzJWFRUABEJPMVYCSEIIbWFya3VwMVYITUMxNTEzVjIITUMxNTEzVjMITUMxNTEzVjQFTUNEM1YFTUNENFYFTUNENVYITUNEMTgxNlYJTUNEMjAxOFYxBk1MUlQyVgZNTFJUM1YGTUxSVDRWBU1NQzJWBE9SMlYET1IzVgVWNTVWMQVZQVMxVgVZQVMyVhQrAxVnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2cWAWZkAhsPDxYEHwAFD01pbHRvbiBQcmludGVycx8BZ2RkAh0PEA8WAh8BZ2QQFQoGbXByMDIxBm1wcjAyNgZtcHIwMzcGbXByMDQ3Bm1wcjA1NgZtcHIwNTgGbXByMDU5Bm1wcjA2MQZtcHIwNjQKS1RlbXBQcmludBUKBm1wcjAyMQZtcHIwMjYGbXByMDM3Bm1wcjA0NwZtcHIwNTYGbXByMDU4Bm1wcjA1OQZtcHIwNjEGbXByMDY0CktUZW1wUHJpbnQUKwMKZ2dnZ2dnZ2dnZxYBZmQCHw8PFgIfAGVkZAIjDxBkEBUFBkJvbHRvbgZNaWx0b24KTHV4ZW1ib3VyZwhTaGFuZ2hhaQdDaGVubmFpFQUDMDY1AzI0MAM0NjADODE4AzcyMBQrAwVnZ2dnZxYBAgFkAgcPZBYCAgEPZBYCZg9kFgYCAQ9kFgYCAQ9kFgICAQ9kFgICAw88KwARAgEQFgAWABYADBQrAABkAgIPZBYCAgEPZBYEAgEPPCsACwBkAgMPPCsACwBkAgMPZBYCAgEPZBYCAgEPPCsACwBkAgMPDxYCHwBlZGQCBQ8WAh8BZxYCAgUPZBYCZg9kFgICAw8QZA8WFGYCAQICAgMCBAIFAgYCBwIIAgkCCgILAgwCDQIOAg8CEAIRAhICExYUEAUBMQUBMWcQBQEyBQEyZxAFATMFATNnEAUBNAUBNGcQBQE1BQE1ZxAFATYFATZnEAUBNwUBN2cQBQE4BQE4ZxAFATkFATlnEAUCMTAFAjEwZxAFATEFATFnEAUBMgUBMmcQBQEzBQEzZxAFATQFATRnEAUBNQUBNWcQBQE2BQE2ZxAFATcFATdnEAUBOAUBOGcQBQE5BQE5ZxAFAjEwBQIxMGdkZBgDBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WBQUmY3RsMDAkQ29udGVudFBsYWNlSG9sZGVyVGl0bGUkY2JMYXRlc3QFJWN0bDAwJENvbnRlbnRQbGFjZUhvbGRlclRpdGxlJGliV29ybGQFJ2N0bDAwJENvbnRlbnRQbGFjZUhvbGRlck1haW4kdGFiUXVlcmllcwUlY3RsMDAkQ29udGVudFBsYWNlSG9sZGVyTWFpbiRpYkRlbGV0ZQUoY3RsMDAkQ29udGVudFBsYWNlSG9sZGVyTWFpbiRpYkRlbGV0ZUFsbAUnY3RsMDAkQ29udGVudFBsYWNlSG9sZGVyTWFpbiR0YWJRdWVyaWVzDw9kZmQFQGN0bDAwJENvbnRlbnRQbGFjZUhvbGRlck1haW4kdGFiUXVlcmllcyRUYWJQYW5lbDIkZ3ZQcm9qZWN0UXVlcnkPZ2SKfow5sXHeelH/7dd04nySzwJ/EyXxJp1Ah2lHDjTXtQ==" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
    theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/DataExchange/WebResource.axd?d=nweBekBjvlBlgfpRmpksATBVdPd9galW18Hn5KPg2mZmjXOWJjdVXyecgyl1cBzgzTNVMBo5S7Jb0xCFVSy8pR3WgUpx20UaenBfvSw-cqw1&amp;t=636396482620000000" type="text/javascript"></script>


<script src="/DataExchange/ScriptResource.axd?d=tLddprAqVo7MnXPWJZ2MI800-sQ61LqVl5ZA5iCWdHkFyOQRDRcMS8MnC7cJt8MwXYKGfXsbgdIPTzvWVczshIOqheggkHH449sgjNgc5fiWLJ1GD8j9YZguNMbD_8TxGJ0gxMwaaOdnP172DSU0CEPMJNFnmAdxaenr1uvBGY6nu9iD4amOqwKRdeUAnR640&amp;t=ffffffffd5bd3df4" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
//]]>
</script>

<script src="/DataExchange/ScriptResource.axd?d=KfphglXbV8kw1oLp3TEodoD6y_0bVEVYkKPagVyYfncZd2TnEvAWXaSDoe9FUQCo8h12LjeYYsQR5khbsILUkGTOg3GfODDdFimzFlF1t5JidBQ3y_vyRNOCJr9l4v89mtUE_RY1Wd-qDVZBkVUvLqfKCjGUi0ZPk-zL0kHTHwtUHd71568WOLlbJG9-gTNp0&amp;t=ffffffffd5bd3df4" type="text/javascript"></script>
<script src="/dataexchange/default.aspx?_TSM_HiddenField_=ctl00_ScriptManager_HiddenField&amp;_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d3.0.20820.16776%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3aen-US%3af5fccc97-14d6-483a-9f55-6aa6527d86a1%3ae2e86ef9%3a1df13a87%3aee0a475d%3ac4c00916" type="text/javascript"></script>
<div>

 <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="9948C718" />
</div>
    <script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl00$ScriptManager', 'aspnetForm', ['tctl00$ContentPlaceHolderTitle$update1','','tctl00$ContentPlaceHolderMain$UpdatePanel2',''], [], [], 90, 'ctl00');
//]]>
</script>
    
    <script type="text/javascript" language="javascript">
        var prm = Sys.WebForms.PageRequestManager.getInstance();

        prm.add_initializeRequest(InitializeRequest);
        prm.add_endRequest(EndRequest);

        function InitializeRequest(sender, args) {
            $get('content').style.cursor = 'wait';
            $get('headershadow').style.cursor = 'wait';

            document.body.style.cursor = 'wait';

//            try { $get(args._postBackElement.id).disabled = true;
//            } catch (err) { 
//                // do nothing
//            }                                    

        }

        function EndRequest(sender, args) {
            $get('content').style.cursor = 'auto';
            $get('headershadow').style.cursor = 'auto';     

            document.body.style.cursor = 'default'; 
//            try { $get(sender._postBackSettings.sourceElement.id).disabled = false;
//            } catch (err) {
//                // do nothing           
//            }            

        }
    </script>
    <div id="header">
        <div id="logo">
            <img alt="" id="huskylogo" src="images/HuskyLogo.png" style="border-style: none;
                border-color: inherit; border-width: medium;" />
        </div>
        <div id="menu">
            <span id="ctl00_lblTitle" style="color:Black;font-size:X-Large;font-weight:normal;">Husky Data Exchange</span>
        </div>
    </div>
    <div id="headershadow">
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td width="100%" valign="bottom" style="background: url(images/banner11.png) repeat-x">
                    
    <div id="ctl00_ContentPlaceHolderTitle_update1">
 
            <table style="width: 100%">
                <tr>
                    <td style="height: 30px; width: 75%">
                        <span id="ctl00_ContentPlaceHolderTitle_lbItemProject" style="font-weight:normal;">Item #:</span>
                        <input name="ctl00$ContentPlaceHolderTitle$tbNumber" type="text" id="ctl00_ContentPlaceHolderTitle_tbNumber" style="width:125px;" />
                        
                        
                        <input type="submit" name="ctl00$ContentPlaceHolderTitle$btnFind" value="Find" id="ctl00_ContentPlaceHolderTitle_btnFind" />
                        <span title="Retrieve only the latest released revision"><label for="ctl00_ContentPlaceHolderTitle_cbLatest"> Latest:</label><input id="ctl00_ContentPlaceHolderTitle_cbLatest" type="checkbox" name="ctl00$ContentPlaceHolderTitle$cbLatest" checked="checked" onclick="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl00$ContentPlaceHolderTitle$cbLatest\&#39;,\&#39;\&#39;)&#39;, 0)" /></span>
                        
                        
                        
                        
                        
                        
                        <input type="image" name="ctl00$ContentPlaceHolderTitle$ibWorld" id="ctl00_ContentPlaceHolderTitle_ibWorld" title="Click to home change site" src="images/world.jpg" style="width:21px;border-width:0px;" />
                    </td>
                    <td align="center">
                        <span id="ctl00_ContentPlaceHolderTitle_lblPrinters">Milton Printers</span>
                        <select name="ctl00$ContentPlaceHolderTitle$ddlPrinters" id="ctl00_ContentPlaceHolderTitle_ddlPrinters">
  <option selected="selected" value="mpr021">mpr021</option>
  <option value="mpr026">mpr026</option>
  <option value="mpr037">mpr037</option>
  <option value="mpr047">mpr047</option>
  <option value="mpr056">mpr056</option>
  <option value="mpr058">mpr058</option>
  <option value="mpr059">mpr059</option>
  <option value="mpr061">mpr061</option>
  <option value="mpr064">mpr064</option>
  <option value="KTempPrint">KTempPrint</option>

 </select>
                        
                    </td>
                </tr>
                <tr>
                    <td style="height: 30px" align="center" colspan="2">
                        <span id="ctl00_ContentPlaceHolderTitle_lblWarningMsg" style="color:Red;font-weight:bold;"></span>
                        
                    </td>
                </tr>
            </table>
        
</div>

                </td>
            </tr>
        </table>
    </div>
    <div id="content">
        
    <div>
    </div>
    <div id="ctl00_ContentPlaceHolderMain_UpdatePanel2">
 
            <table id="TabTable" style="border-top-style: none; border-right-style: none; border-left-style: none;
                border-bottom-style: none" align="left" width="100%">
                <tr>
                    <td align="left" style="width: 75%" valign="top">
                        &nbsp;
                        <div id="ctl00_ContentPlaceHolderMain_tabQueries" class="ajax__tab_xp" style="border-style:None;width:100%;visibility:hidden;">
  <div id="ctl00_ContentPlaceHolderMain_tabQueries_header">
   <span id="__tab_ctl00_ContentPlaceHolderMain_tabQueries_TabPanel1">
                                    <span id="ctl00_ContentPlaceHolderMain_tabQueries_TabPanel1_lbDrawing">Drawing Query</span>
                                </span><span id="__tab_ctl00_ContentPlaceHolderMain_tabQueries_TabPanel2">
                                    <span id="ctl00_ContentPlaceHolderMain_tabQueries_TabPanel2_lbProject">Project Query</span>
                                </span><span id="__tab_ctl00_ContentPlaceHolderMain_tabQueries_TabPanel3">
                                    <span id="ctl00_ContentPlaceHolderMain_tabQueries_TabPanel3_lbManufacturinData">Manufacturing Data</span>
                                </span><span id="__tab_ctl00_ContentPlaceHolderMain_tabQueries_TabPanel4">
                                    PTP Times
                                </span>
  </div><div id="ctl00_ContentPlaceHolderMain_tabQueries_body">
   <div id="ctl00_ContentPlaceHolderMain_tabQueries_TabPanel1" style="display:none;visibility:hidden;">
    
                                    <br />
                                    
                                    <table id="dummyTableNEEDED2KeepRepeaterWorkingWithTabControl" style="border-style: none">
                                        <tr>
                                            <td>
                                            </td>
                                        </tr>
                                    </table>
                                    <br />
                                
   </div><div id="ctl00_ContentPlaceHolderMain_tabQueries_TabPanel2" style="display:none;visibility:hidden;">
    
                                    <table width="100%" style="border-style: none">
                                        <tr>
                                            <td valign="top">
                                                <span id="ctl00_ContentPlaceHolderMain_tabQueries_TabPanel2_lblProjectNo"></span>
                                                <div>

    </div>
                                            </td>
                                        </tr>
                                    </table>
                                
   </div><div id="ctl00_ContentPlaceHolderMain_tabQueries_TabPanel3" style="display:none;visibility:hidden;">
    
                                    <table width="100%" style="border-style: none">
                                        <tr>
                                            <td valign="top">
                                                
                                            </td>
                                            <td align="center">
                                                
                                            </td>
                                        </tr>
                                    </table>
                                
   </div><div id="ctl00_ContentPlaceHolderMain_tabQueries_TabPanel4" style="display:none;visibility:hidden;">
    
                                    <table width="100%" style="border-style: none">
                                        <tr>
                                            <td>
                                            <td align="center">
                                                
                                            </td>
                                        </tr>
                                    </table>
                                
   </div>
  </div>
 </div>
                        <span id="ctl00_ContentPlaceHolderMain_lblQueryTime"></span>
                    </td>
                    <td align="right" valign="top">
                        &nbsp;
                        <table id="ctl00_ContentPlaceHolderMain_tblDatalist" border="1" cellpadding="1" cellspacing="1" class="clsHeader" width="150" style="border-color: black; height: 280px; text-align: center">
  <tr>
   <th style="height: 21px">
                                    Data List:
                                </th>
  </tr>
  <tr class="clsField">
   <th>
                                    Your Revisions
                                </th>
  </tr>
  <tr class="clsRecord">
   <td style="border-bottom-style: none; height: 120px" valign="top" align="center">
                                    <select size="6" name="ctl00$ContentPlaceHolderMain$lbDataListItems" id="ctl00_ContentPlaceHolderMain_lbDataListItems" style="height:110px;width:125px;">

   </select>
                                </td>
  </tr>
  <tr>
   <td style="border-top-style: none; background-color: window;" align="center">
                                    <input type="image" name="ctl00$ContentPlaceHolderMain$ibDelete" id="ctl00_ContentPlaceHolderMain_ibDelete" src="images/delete.JPG" style="border-width:0px;" />
                                    <input type="image" name="ctl00$ContentPlaceHolderMain$ibDeleteAll" id="ctl00_ContentPlaceHolderMain_ibDeleteAll" src="images/delete_all.JPG" style="border-width:0px;" />
                                </td>
  </tr>
  <tr class="clsRecord">
   <td style="border-bottom-style: none">
                                    <input type="submit" name="ctl00$ContentPlaceHolderMain$btnEmailAll" value="E-Mail All Revisions" id="ctl00_ContentPlaceHolderMain_btnEmailAll" disabled="disabled" style="width:150px;" />
                                </td>
  </tr>
  <tr>
   <td align="center" style="border-top-style: none; vertical-align: top; background-color: #ffffff;">
                                    <span id="ctl00_ContentPlaceHolderMain_lblQty">Qty:</span>
                                    <select name="ctl00$ContentPlaceHolderMain$ddlQty" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl00$ContentPlaceHolderMain$ddlQty\&#39;,\&#39;\&#39;)&#39;, 0)" id="ctl00_ContentPlaceHolderMain_ddlQty">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>

   </select>
                                    <input type="submit" name="ctl00$ContentPlaceHolderMain$btnPrintAll" value="Print All" id="ctl00_ContentPlaceHolderMain_btnPrintAll" disabled="disabled" style="width:80px;" />
                                </td>
  </tr>
 </table>
 
                    </td>
                </tr>
            </table>
        
</div>

    </div>
    <div id="footer">
        <p>
            <span class="FieldHeader">Contact <a href="mailto:+Helpdesk">+Helpdesk</a> with any
                technical issues.</span>
            <br />
            &copy; 2012 Husky Injection Molding Systems.
        </p>
    </div>
    

<script type="text/javascript">
//<![CDATA[
Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.TabPanel, {"headerTab":$get("__tab_ctl00_ContentPlaceHolderMain_tabQueries_TabPanel1")}, null, {"owner":"ctl00_ContentPlaceHolderMain_tabQueries"}, $get("ctl00_ContentPlaceHolderMain_tabQueries_TabPanel1"));
});
Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.TabPanel, {"headerTab":$get("__tab_ctl00_ContentPlaceHolderMain_tabQueries_TabPanel2")}, null, {"owner":"ctl00_ContentPlaceHolderMain_tabQueries"}, $get("ctl00_ContentPlaceHolderMain_tabQueries_TabPanel2"));
});
Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.TabPanel, {"headerTab":$get("__tab_ctl00_ContentPlaceHolderMain_tabQueries_TabPanel3")}, null, {"owner":"ctl00_ContentPlaceHolderMain_tabQueries"}, $get("ctl00_ContentPlaceHolderMain_tabQueries_TabPanel3"));
});
Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.TabPanel, {"headerTab":$get("__tab_ctl00_ContentPlaceHolderMain_tabQueries_TabPanel4")}, null, {"owner":"ctl00_ContentPlaceHolderMain_tabQueries"}, $get("ctl00_ContentPlaceHolderMain_tabQueries_TabPanel4"));
});
Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.TabContainer, {"activeTabIndex":0,"autoPostBackId":"ctl00$ContentPlaceHolderMain$tabQueries","clientStateField":$get("ctl00_ContentPlaceHolderMain_tabQueries_ClientState")}, null, null, $get("ctl00_ContentPlaceHolderMain_tabQueries"));
});
//]]>
</script>
</form>
</body>
</html>

CPAU Script:

c:
cd Manufacturingdata
CPAU.exe -dec -file manufacturingdata.job -hide

Thanks in advance!

rosi97
  • 243
  • 3
  • 18
  • Does the Url of the PDF file change according to the input? If so, you can most likely directly download the PDF file instead of all this horrible background IE nonsense. – Reinstate Monica Cellio Mar 07 '18 at 17:43
  • Example: https://stackoverflow.com/questions/43316888/how-to-download-pdf-file-from-intranet-in-net – Reinstate Monica Cellio Mar 07 '18 at 17:44
  • Unfortunately not. I only get the "Open,Save and SaveAs" dialog – rosi97 Mar 07 '18 at 17:44
  • 1
    Incidentally, off-site code is useless here. The question must be self-contained - [mcve] – Reinstate Monica Cellio Mar 07 '18 at 17:44
  • @Archer Thank you for pointing that out – rosi97 Mar 07 '18 at 17:52
  • @Andrew Morton I cant add code to the server. – rosi97 Mar 07 '18 at 19:22
  • 1
    OK, there are two other possibilities that come to mind at the moment: the inferior one is to host a WebBrowserControl in the VB program. The best one is to find out what is being sent to the web page - [Show sent POST Values with Fiddler..How do i do that?](https://stackoverflow.com/q/6939681/1115360) - and then craft your own interaction with the server, e.g. [How to make HTTP POST web request](https://stackoverflow.com/q/4015324/1115360). – Andrew Morton Mar 07 '18 at 20:36
  • @AndrewMorton I found the POST values which are sent to receive the files. But I cant find any authentication. I think the problem will be that I need to run IE with other credentials (CPAU/RUNAS) to visit the site. And I guess that is not possible with the WebBrowser Control. – rosi97 Mar 08 '18 at 15:51
  • @rosi97 If someone was getting the file by only using a browser and not using your script, would they have to log in to get the PDF? If so, could you have them enter their credentials in an ordinary Windows Form, or are the credentials secret from the users? – Andrew Morton Mar 08 '18 at 16:25
  • @AndrewMorton The CPAU script only starts/opens a new IE session with other credentials. Only by using the script the user is able to receive files from the server. If you would try getting the files without the script, the request would just time out. The credentials are always the same and known. But I'm not sure which authentication is used since I'm not very familiar with HTTP. I tried only sending the POST values for receiving the .pdf file which I got from fiddler, but I then get "401 Unauthorized" from our intranet server. – rosi97 Mar 08 '18 at 17:10
  • @AndrewMorton Okay, the authentication seems to be NTLM, so I think I could work with https://learn.microsoft.com/en-us/dotnet/framework/network-programming/ntlm-and-kerberos-authentication. Do I need to mimic all the `GET` and `POST` I got through fiddler, in my vb.net application to receive my files ? Or just the authentication and the `POST` for actually receiving the file. – rosi97 Mar 08 '18 at 20:38
  • @rosi97 Have you seen [Making a web request to a web page which requires windows authentication](https://stackoverflow.com/q/3562979/1115360)? – Andrew Morton Mar 09 '18 at 09:48
  • @AndrewMorton Yes, that did the job perfectly fine. I’m now authorized on the server, did the required POST Request and can now receive the pdf filestream. Thank you very much! Post that as a answer, so I can mark it as the solution. – rosi97 Mar 10 '18 at 03:01
  • @rosi97 I've done that. Perhaps you could edit your question to include the other information that you gave in comments: you can't add code to the server, and you need to use NTLM authentication, so then we can delete a load of these comments (hover over your comments to see the X) to keep it tidy. – Andrew Morton Mar 10 '18 at 10:55

1 Answers1

0

This will require the use of the information from two other answers.

To replace the browser interaction, you can can create a POST request programmatically, as shown in How to make HTTP POST web request.

As you also need NTLM authentication with the request, you will need to add in the information from Making a web request to a web page which requires windows authentication.

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84