Hi, I'm using webclient to enable download of files.
However, files get copied to the server rather than the
client machine. What could be the problem.
Here is the sample that I've used:
WebClient myWebClient = new WebClient();
myWebClient.Dow nloadFile
("http://www.myweb.com/testfile.txt" ,"c:/test.txt");
The problem is that the test.txt gets copied to the C:\
drive of the server rather than the client machine. 2 2986
Are you running this in an ASP.Net page? Then of course it's going to
download to the server because the code will only run on the server. To get
this to work like you want you would need to be executing this as a program
on the client computer.
You can always use a response.writef ile to the browser. You can't control
where it's saved on the user's machine, and basically it will work exactly
the same as if you made a link to the file (ie: text files will probably be
opened in the browser since the browser knows what to do with them, try
zipping the file so user's are prompted for download).
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"r dubey" <to******@yahoo .com> wrote in message
news:03******** *************** *****@phx.gbl.. . Hi, I'm using webclient to enable download of files. However, files get copied to the server rather than the client machine. What could be the problem.
Here is the sample that I've used:
WebClient myWebClient = new WebClient(); myWebClient.Dow nloadFile ("http://www.myweb.com/testfile.txt" ,"c:/test.txt");
The problem is that the test.txt gets copied to the C:\ drive of the server rather than the client machine.
try this one^_^¡£
1.get file from dataserver ,and save it into web server'harddisk
2.client get file from web server
private void BT_DownFile_Cli ck(object sender, System.EventArg s e)
{
string str="SELECT CONTENT,FILE_NA ME FROM FILES WHERE STS='A' AND
FILE_ID="+Reque st.QueryString ["FILE_ID"].ToString();
OleDbCommand myCommand=new OleDbCommand (str,myConnecti on);
if(myConnection .State.ToString ().ToUpper()!=" OPEN")
myConnection.Op en();
OleDbDataReader myReader=myComm and.ExecuteRead er();
if (myReader.Read( ))
{
string filename=myRead er.GetString(1) ;
byte[] FileData = (byte[])myReader["CONTENT"];//ÀàÐÍת»¯
string
filedirect=Conf igurationSettin gs.AppSettings["TmpDirForDownL oad"].ToString()
+"\\"+Request.Q ueryString ["FILE_ID"].ToString();
DirectoryInfo DirInfo=new DirectoryInfo(f iledirect);//´´Ä¿Â¼
if (!DirInfo.Exist s)
Directory.Creat eDirectory(file direct);
string fullname=filedi rect+"\\"+filen ame;//ºÏÈ«²¿ÎļþÃû
if(!System.IO.F ile.Exists(full name))//Èç¹ûÎļþ²»´æÔÚÔ ÙдÎļþ,·ñÔò²»Ö Øд
ÁË
{
FileStream fs=System.IO.Fi le.Create(fulln ame);//дÎļþ
fs.Write(FileDa ta,0,FileData.L ength);
fs.Close();
}
System.IO.FileI nfo fi=new System.IO.FileI nfo(fullname);
Response.Clear( );
Response.AddHea der("Content-Disposition","a ttachment;filen ame="+HttpUtili ty.
UrlEncode(fi.Na me));
Response.AddHea der("Content-Length",fi.Leng th.ToString()) ;
Response.Conten tType="applicat ion/octet-stream" ;
Response.WriteF ile(fi.FullName );
Response.End();
}
myReader.Close( );
}
--
ͯÕñ»ª
Zhejiang Innovation Central Software Co., Ltd.
Address:6/F Bd.18 Software Park,176 Tianmushan Rd.,Hangzhou,31 0007 P.R.C This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marcel Brekelmans |
last post by:
Hi,
This is my situation:
My ISP doesn't allow me the execute server-code. So, no ASP or otherwise.As
a small compensation, they run some CGI scripts that we can use. With one of
these scripts I maintain a set of counters, one on each of my HTML pages
that they host. It is all very basic, the files are no more then textfiles
that ONLY...
|
by: Swaregirl |
last post by:
Hello,
I would like to build a website using ASP.NET. I would like website
visitors to be able to download code that I would like to make available to
them and that would be residing on my personal server.
Are there any code samples or books that someone can recommend so that I can
implement this. I would prefer VB.NET code, but I am...
|
by: JD |
last post by:
Does anyone know of any component out in the market that will allow you
analyze IIS weblogs, I have been asked to develop a tool for a client that
will do this for them, and the one that came to mind was webtrends. However,
they don't want to buy this software....I don't know of any component that
will do this, but if anyone can help I would...
|
by: Cheryl Langdon |
last post by:
Hello everyone,
This is my first attempt at getting help in this manner. Please
forgive me if this is an inappropriate request.
I suddenly find myself in urgent need of instruction on how to
communicate with a MySQL database table on a web server, from inside
of my company's Access-VBA application. I know VBA pretty well but
have never...
|
by: David Golightly |
last post by:
This is just a quick poll for all you web devs out there: What
browsers do you test on/are concerned about compatibility with?
Obviously, you're going to test on current-generation browsers such as
IE6, IE7, Firefox 1.5/2, Opera 8/9, Safari 2, etc.
How old must a browser be before you stop worrying about it? Anybody
here still test on...
| |
by: Bob Jones |
last post by:
Here is my situation:
I have an aspx file stored in a resource file. All of the C# code is
written inline via <script runat="server"tags. Let's call this page
B. I also have page A that contains some javascript code that calls
window.open. I pass the resource url of page B to Page A's window.open
call. Page B is then loaded and executed but...
|
by: skinymike |
last post by:
when i allow user to download a media file such as midi or wav files. It automatically open the files using Windows Media Player. Its fine works ok.
But when i allow user to download a theme files such as *.sis or *.thm , Windows does have the software to open file such as sis or thm. But the Popup menu doesnt show Save Open Cancel. It used to...
|
by: Lennert |
last post by:
DutchPIPE beta 0.4.0
PHP version 5 & AJAX
With DutchPIPE open source software, web developers can make virtual
multi-user environments. Each web page becomes an abstracted
environment or location where visitors and other items on the page are
visualized. This status is retained as visitors move around. A lot of
real-time interaction is...
|
by: The Bicycling Guitarist |
last post by:
Hello. I have many songs and essays pages that have been online more than
ten years in some cases. These pages use HTML and CSS. Is there some way to
allow visitors to add comments to these pages, the way most blogs allow
comments by visitors? Of course I want the capability of deleting spam.
Would migrating to a content management system do...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |