Click here to Skip to main content
15,887,355 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I m woking on a web application that logins on another website and then downloads some files from that site just on a click of a button.

I have already implemented the logic to login on that website and am also able to see the protected page of that site.

Now that website is returning an HTML code that has the filename i want to download under <script> tag

<script>PrintFileURL("13572_BranchInformationReport_2012-05-22.zip","13572_BranchInformationReport_2012-05-22.zip",0,"184601","May 22 1:30","/icons/default.gif")</script>

the method called is

C#
function PrintFileURL(uri, name, dirFlag, filesize, time, icon)
               {
                    var color
                    var bgcolor
                    if(!(name.length>2 && name.charAt(name.length-1)=="e" && name.charAt(name.length-2)==".")) {
                         if (lineColor)
                         {
                              bgcolor="EEEEEE"
                              lineColor=false
                         }
                         else
                         {
                              bgcolor="FFFFFF"
                              lineColor=true
                         }
                         document.write("<tr bgcolor=" + bgcolor + ">");
                         if (dirFlag)
                         {
                              document.write("<td nowrap=""><img src='" + icon + "'><a href="" + uri +<br mode="hold" />                                   "/?T"> " + name + "</a></td>");
                              document.write("<td> </td>");
                              document.write("<td> </td>");
                              document.write("<td> </td>");
                         }
                         else
                         {
                              document.write("<td nowrap=""><img src='" + icon + "'><a href="" + uri +<br mode="hold" />                                   ""> " + name + "</a></td>");
                              document.write("<td><font face="Arial" size="2">" + filesize +
                                   "</font></td>");
                              document.write("<td><font face="Arial" size="2">" + time +
                                   "</font></td>");
                              document.write("<td> </td>");
                         }
                         document.write("</tr>");
                    }
               }


I am totally stuck here. Can someone help.

Thanks in advance

Regards,
Akhil
Posted
Updated 22-Jun-12 0:13am
v2

1 solution

Here you see the code

C#
public void downloadFile(string Url, string filePath)
       {
           if (File.Exists(filePath))
           {
               File.Delete(filePath);
           }
           //Downloading file form Http Url
           WebClient myWebClient = new WebClient();
           myWebClient.DownloadFile(url, filePath);
           //CompleteDownloading file form Http Url

}

In the above code ,In place of url=,"13572_BranchInformationReport_2012-05-22.zip",0,"184601","May 22 1:30","/icons/default.gif" and in filepath put the path to save the download file
 
Share this answer
 
v2
Comments
akhilgaur1988 22-Jun-12 7:09am    
its throwing exception "The given path's format is not supported."
akhilgaur1988 22-Jun-12 7:14am    
and thats the main problem.....

How to get the url of the file i want to download...
Kamalkant(kk) 22-Jun-12 7:21am    
You have first know the url ,then download
akhilgaur1988 22-Jun-12 8:08am    
Above javascript function is included in the html file i m getting while reading the website using streamreader. now i need to find some way to get that file name included in script tag and then write some C# code to download that file.

How can i search for the Above javascript function is included in the html file i m getting while reading the website using streamreader. now i need to find some way to get that file name included in script tag and then write some C# code to download that file.

The names are included in script tag starting with "<script>PrintFileURL("
How can i get the names of all the files included in the tag?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900