473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

File download help

I am wondering how I can create like a dynamic hyperlink using C#. I am
working with asp.net 2.0 and iis5 on windows 2000 server. I am creating
a file in a program that I have which needs to be downloaded at the end
of the program. Like when the program is done running the user right
clicks on the link and then checks save as and then it's on there
computer. Only thin is that the file name to be downloaded is going to
change with each run of the program. I was wondering if anyone knew
where some code was, or could give me a little sample of how to work
this. Thanks a ton for help.

Aug 10 '06 #1
4 1473
Hi Millhouse,

I think you may need to explain in more detail.

Do you mean you have a web application with a link to a file, and the file
is created when the web application runs some program?
You can always set the link during postback, or use
Response.WriteFile/TransmitFile.
On Thu, 10 Aug 2006 22:51:40 +0200, Millhouse50 <os**********@gmail.com>
wrote:
I am wondering how I can create like a dynamic hyperlink using C#. I am
working with asp.net 2.0 and iis5 on windows 2000 server. I am creating
a file in a program that I have which needs to be downloaded at the end
of the program. Like when the program is done running the user right
clicks on the link and then checks save as and then it's on there
computer. Only thin is that the file name to be downloaded is going to
change with each run of the program. I was wondering if anyone knew
where some code was, or could give me a little sample of how to work
this. Thanks a ton for help.


--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 11 '06 #2
Yeah this would be at the end of a web app. I am using the wizard
control from asp.net nad have four pages to the wizard. I am trying to
take the user entered url given in text box on first page, and by the
time i'm done with the app I need to download that file as a .pfx. So
something like www.go.com.pfx, but the URL changes everytime the user
runs the app, so I need to make the link dynamic so when the user
clicks the finish button on the wizard app the .pfx will be created and
there will be a link on a completion page where you can download it.



Morten Wennevik wrote:
Hi Millhouse,

I think you may need to explain in more detail.

Do you mean you have a web application with a link to a file, and the file
is created when the web application runs some program?
You can always set the link during postback, or use
Response.WriteFile/TransmitFile.
On Thu, 10 Aug 2006 22:51:40 +0200, Millhouse50 <os**********@gmail.com>
wrote:
I am wondering how I can create like a dynamic hyperlink using C#. I am
working with asp.net 2.0 and iis5 on windows 2000 server. I am creating
a file in a program that I have which needs to be downloaded at the end
of the program. Like when the program is done running the user right
clicks on the link and then checks save as and then it's on there
computer. Only thin is that the file name to be downloaded is going to
change with each run of the program. I was wondering if anyone knew
where some code was, or could give me a little sample of how to work
this. Thanks a ton for help.

--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 11 '06 #3
Here is some of the code that I have. I have a bit of a different
question now though. I was wondering if I could put a timeout event
right before it executes the DownloadFile code so that my program can
wait and make sure that the file is created to be downloaded
psi.CreateNoWindow = true;
System.Diagnostics.Process.Start(psi);
certnameLabel.Text = urlTextBox.Text;
certcityLabel.Text = cityTextBox.Text;
certstateLabel.Text = stateTextBox.Text;
certcountryLabel.Text = countryTextBox.Text;
DownloadFile(File, true);

private void DownloadFile(string fname, bool forceDownload)
{
string path = MapPath(fname);
string name = Path.GetFileName(path);
string ext = Path.GetExtension(path);
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".pfx":
type = "application/x-pkcs12";
break;
}
}
if (forceDownload)
{
Response.AppendHeader("content-disposition",
"attachment; filename=" + name);
}
if (type != "")
Response.ContentType = type;
Response.WriteFile(path);
Response.End();


Morten Wennevik wrote:
Hi Millhouse,

I think you may need to explain in more detail.

Do you mean you have a web application with a link to a file, and the file
is created when the web application runs some program?
You can always set the link during postback, or use
Response.WriteFile/TransmitFile.
On Thu, 10 Aug 2006 22:51:40 +0200, Millhouse50 <os**********@gmail.com>
wrote:
I am wondering how I can create like a dynamic hyperlink using C#. I am
working with asp.net 2.0 and iis5 on windows 2000 server. I am creating
a file in a program that I have which needs to be downloaded at the end
of the program. Like when the program is done running the user right
clicks on the link and then checks save as and then it's on there
computer. Only thin is that the file name to be downloaded is going to
change with each run of the program. I was wondering if anyone knew
where some code was, or could give me a little sample of how to work
this. Thanks a ton for help.

--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 11 '06 #4
I was thinking of monitoring the directory, and for windows applications
you could then be notified when the file is made, but I'm not sure this
will work for web applications. A couple of other solutions might be to
hold page_load until the file is made, maybe polling the directory, or set
the page to update itself in n seconds, making sure to give a large enough
time span to ensure the file is made.

Easiest method is probably to hold the web page until the file is made.
Possibly showing an animated gif while waiting.
On Fri, 11 Aug 2006 16:39:38 +0200, Millhouse50 <os**********@gmail.com>
wrote:
Here is some of the code that I have. I have a bit of a different
question now though. I was wondering if I could put a timeout event
right before it executes the DownloadFile code so that my program can
wait and make sure that the file is created to be downloaded
psi.CreateNoWindow = true;
System.Diagnostics.Process.Start(psi);
certnameLabel.Text = urlTextBox.Text;
certcityLabel.Text = cityTextBox.Text;
certstateLabel.Text = stateTextBox.Text;
certcountryLabel.Text = countryTextBox.Text;
DownloadFile(File, true);

private void DownloadFile(string fname, bool forceDownload)
{
string path = MapPath(fname);
string name = Path.GetFileName(path);
string ext = Path.GetExtension(path);
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".pfx":
type = "application/x-pkcs12";
break;
}
}
if (forceDownload)
{
Response.AppendHeader("content-disposition",
"attachment; filename=" + name);
}
if (type != "")
Response.ContentType = type;
Response.WriteFile(path);
Response.End();


Morten Wennevik wrote:
>Hi Millhouse,

I think you may need to explain in more detail.

Do you mean you have a web application with a link to a file, and the
file
is created when the web application runs some program?
You can always set the link during postback, or use
Response.WriteFile/TransmitFile.
On Thu, 10 Aug 2006 22:51:40 +0200, Millhouse50 <os**********@gmail.com>
wrote:
I am wondering how I can create like a dynamic hyperlink using C#. I
am
working with asp.net 2.0 and iis5 on windows 2000 server. I am
creating
a file in a program that I have which needs to be downloaded at the
end
of the program. Like when the program is done running the user right
clicks on the link and then checks save as and then it's on there
computer. Only thin is that the file name to be downloaded is goingto
change with each run of the program. I was wondering if anyone knew
where some code was, or could give me a little sample of how to work
this. Thanks a ton for help.

--
Happy Coding!
Morten Wennevik [C# MVP]


--
Happy Coding!
Morten Wennevik [C# MVP]
Aug 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ASP Spam Fighter | last post by:
Hello all, I don't know how to get around this one... If anybody can help me with this problem, I would appreciate it very much. I've been trying to send a (large) file to the browser via a...
0
by: jmd | last post by:
Hello. I want to write a C# program that does completely automatically what, until now, I do manually, witch is describe below : 1. I launch IE (6) 2. I browse to my desired download page, say...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
5
by: Bala | last post by:
Hi I displaying my pdf files ( F:\test\test1\test.pdf - for example file path) on datagrid for user download. when I right clik the link and its show like this file:///F:/test/test1/test.pdf....
18
by: jmd | last post by:
Hello, I posted the following in the C# forum but without one answer. But perhaps now in vb.net someone has some guidelines ! This is my question : I want to write a vb.net program that does...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
4
by: Roberto Mora | last post by:
I have not done programming in a very long time and what is worst, I never learned VB. Although my job does not require this knowledge, I cam across a problem that although it seemed simple it has...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.