Home > Software design >  Create simple webpage (IIS) that accepts a value from hyperlink and offers the value as a file downl
Create simple webpage (IIS) that accepts a value from hyperlink and offers the value as a file downl

Time:06-05

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?

CodePudding user response:

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>";
}

CodePudding user response:

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.

  • Related