skip to Main Content

The page or script or whatever will be hosted on IIS and should basically accept a value from an hyperlink www.whatever.com?parametervalue=test and offer a file download with for example the name, myfile.file, containing the value ‘test’.

The parametervalue should have not characterlimit in the URL because it’s possible that the value that is passed is a very long string with 4000 characters or more.

I am not sure how to go about this. What technology can I use to get this done, html/javascript perhaps? I have tried Google’ing but cannot think of the right combination of words to pinpoint what I am looking for.

How can I get this done?

2

Answers


  1. If I understood your question well you want to make link so when someone visits it download a file.
    Then you can create download.php file and write there

    if ($_GET["parametervalue"] == "file1") {
    echo "<script>(script to download your file)</script>";
    }
    
    Login or Signup to reply.
  2. Ok, so we have some web page. User clicks on some button. That button can then walk the dog, do payroll, and THEN we also want to take some xml file, and pass that to the next page, in which we offer a download button.

    So, seems VERY little need to use or have or want or even consider using parameters in the URL here. Besides attempting to pass a xml string in a paramter would and could introduce all kinds of issues and probelms.

    So, in first page:

    Button click (why some hyper link???? makes zero sense here).

    that button click as noted can do whatever we want, inclduing that of gettitng and obatining the xml file, and of couse we want to also provide and include a file name for the download.

    so, on that 1st page, dump the use of a hyper link, and use a button.

    That button will

    Get the xml data we want, and save into sesison

     session["XMLData"] = " my messy and ugly xml string/data here";
    
     session["XMLFileName] = "ssrs.xml";
    
     Response.Redirect("MyDownloadpage.aspx"); // jump to page with download button
    

    Now, on the target page, we have that download button.

    That download button can then do this:

    public void DownLoadFile()
    {
    string strXMLData = Session["MyXMLData"] as string;
    string strFile = Session["MyFile"] as string;
    string MineType =  MimeMapping.GetMimeMapping(strFile)
    
    Response.Buffer = false; 
    Response.Clear();
    Response.ClearContent();
    Response.ClearHeaders();
    
    Response.AddHeader("Accept-Header", strXMLData.Length.ToString());
    Response.AddHeader("Content-Length", strXMLData.Length.ToString());
    
    Response.AddHeader("Content-Disposition", "attachment; filename=" + strFile);
    
    Response.AddHeader("Expires", "0");
    Response.AddHeader("Cache-Control", "private");
    Response.ContentType = strMineType;
    Response.AddHeader("Accept-Ranges", "bytes");
    Response.Write(strXMLData);
    Response.Flush();
    Response.End();
    }
    

    So, from the page that jumps to your page with some information and the download button,, you can use code like above.

    To pass the xml data, and the xml file name to be used, you can use session[] as per above.

    Edit: Get the url paramter

    As noted in comments, the xml data is to be passed in the URL, so now the above code becomes this:

        string strXMLData = Request.QueryString["data"];
    

    Of course you replace "data" with whatever the name of the parameter value passed is.

    Or, just grab the first value, say like this:

        string strXMLData = Request.QueryString[0];  // manybe use 1 - depends on what url looks like
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search