Saving a file from the server on to user's PC.

I have a subprocedure where upon clicking on the link button on a webpage,the subprocedure will save data from a datagrid,write it to a text file and save it on to the user's PC.Does anyone know how do i go about doing this?
0
Moose6912
11/4/2004 1:02:13 AM
asp.net.visual-basic.net 3721 articles. 0 followers. Follow

6 Replies
560 Views

Similar Articles

[PageSpeed] 0

Change the content type of the page sending the text to this:

application/octet-stream
Then use Response.Write(ALLTEXT)
Picky
0
pickyh3d
11/5/2004 1:38:11 AM
Hi. I want to do similar things, seting the same content type, but want to change the name of the saved file.

For example, I have a page named "Download.aspx" which generates binary output and the user to be prompted to save the file with name "MyFile.dat". Is it possible?
Thank you in advance.
Best regards.
0
nanestev
11/5/2004 2:46:01 PM
I think the header tag "Content-Disposition" will allow you to provide a default filename.

Check google. http://www.hanselman.com/blog/PermaLink.aspx?guid=360
Picky
0
pickyh3d
11/7/2004 1:43:29 AM
Ok,my code uses this

strPhysicalPath = Server.MapPath(PathVirtual)
'exit if file does not exist
If Not System.IO.File.Exists(strPhysicalPath) _
Then Exit Sub
objFileInfo = New System.IO.FileInfo(strPhysicalPath)
Response.Clear()
'Add Headers to enable dialog display
Response.AddHeader("Content-Disposition", "attachment; filename=" & _
objFileInfo.Name)
Response.AddHeader("Content-Length", objFileInfo.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(objFileInfo.FullName)
PathVirtual is a string which equals "../Records.txt".Sometimes,the download or save dialog box appears,but sometimes the following error appears.
System.UnauthorizedAccessException: Access to the path "D:\IncApps\Records.txt" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) at System.IO.StreamWriter.CreateFile(String path, Boolean append) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) at System.IO.StreamWriter..ctor(String path, Boolean append) at System.IO.File.CreateText(String path) at uiNTUCLink.Report.WriteTextFile()
Can anyone tell me what is the error?
0
Moose6912
12/28/2004 12:59:40 PM
the problem is the "../" which is telling the MapPath function to map a path 1 directory above your webapplicaition's root.  This is a no-no.  you're not allowed to touch files outside your webapplication's directory.  try making PathVirtual = "Records.txt"
0
jeffreyabecker
12/28/2004 2:25:06 PM
Check this : view post 833372

regards
Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
0
haidar_bilal
2/20/2005 10:52:29 AM
Reply:

Similar Artilces:

Visual Basic.NET or Visual Studio.NET?
OK, this has probably been asked before... I'm a student looking to cut my costs, and I can do this by just purchasing Visual Basic.NET as opposed to the fully-fledged Visual Studio.NET application. Of course, I'll only be able to program in VB, but that's fine with me. I wanted to know if all of the ASP.NET specific options are available, such as using a WYSIWYG editor? I'd also like to know if VB.NET has IntelliSense, or that's a specific option only available to Visual Studio.NET users. Thanks in advance. I'd have to believe that VB.Net has intellisense. What is the price d...

Visual Studio .Net? Visual Basic .Net?
Okay, I admit it -- I know nothing about .Net. I'm a Visual Basic and ASP developer. DotNetNuke is my first tentative step into the whole ".Net Thing", and I'm looking for some advice... What do I really need to be able to make some modifications, or new modules for DotNetNuke? Do I need the full, THOUSAND DOLLAR Visual Studio .Net 2003 package, or can I get away with the HUNDRED DOLLAR Visual Basic .Net Standard package?Chameleon Systems, Inc. You can use webmatrix, available here for free. One of the drawbacks of webmatrix however is that it does not support code-be...

Visual Basic.NET or Visual Studio.NET? #2
I am currently using the Web Matrix to develop ASP.NET applications, but I am keep to upgrade to VS.NET. However, I can't justify spending $1,000 at the moment. I then found the MUCH cheaper "Visual Basic .NET 2003 Standard Edition" which is only $100. I have very little C# knowledge, and use Basic almost all the time. Would this be a good tool to use for web development? Does it support all the code behind stuff that VS users love so much? Thanks!! I use "VB.NET Standard Edition" and I'm happy with it. It has exactly the same features as Visual Studio.NET. Th...

Mozilla get's no style tag's from .net server.
I made a webform in web matrix, and it looks fine in IE. If I open the same link whit Mozilla, it looks like a disaster. When I look at the HTML source, there are no style tags as in IE. But when I save the HTML source from IE (the one whit style tags) and open it in Mozilla, it looks perfect. So the onley reason the webform looks wrong in Mozilla, is because the .net server detects Mozilla and not IE and sends a style less HTML source. Wy? Mozilla does support style tags. Is there a solution for this bug? Or is this a uh.. feature? ..Mivz Update, I have got some more info. It is ...

CSV to save on server, (not user's PC)
Hi, I have been using the following article to make a CSV file of a dataset.C:\Documents and Settings\Glyn Aston\Desktop\CSV\New Folder (2)\DotNetBips_com  The _NET Knowledge Base.htmThe CSV file is created on a button click and then the user gets a popup to choose a location to save the file. I want to modify this code to save the file in a set location on the web server. How do I do this?? Thanks You gave us a link to a file on your Hard Drive. I'm assuming your talking about this article http://www.dotnetbips.com/Articles/displayarticle.aspx?id=302 At the end of the article,...

Visual Basic .NET 2003 vs Visual Studio .NET 2003
Hi, If im going to be coding my ASP.NET in just VB.NET then would I be able to go for the cheaper option of buying Visual Basic .NET 2003 ?? - Carl S Yes.Starting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Blog Are there any limitations if I was doing my ASP.NET with VB.NET in Visual Basic .NET 2003 than if I was using the full Visual Studio .NET 2003 ?? Or are the only advantages of Visual Studio .NET 2003 in that it supports more programming languages ?? - Carl S You should check the MS Web site, but I believe that, given an edition (Standard, Professional...

Login failed for user 'Bachelorplace'. The user is not associated with a trusted SQL Server connection. (.Net SqlClient Data Provider)
please tellme how to resolve this error, i m using server studio management tool. and trying to connect using sql server authentication. my pc is over a domain.   Login failed for user 'Bachelorplace'. The user is not associated with a trusted SQL Server connection. (.Net SqlClient Data Provider)  check whether that sql server is allowing sqlauthentication or not.select that server -> right click it-> select  properties  -> in the window, select security -> check what is the server authentication. it should be  sqlserver and windows authentica...

.NET 2.0 file upload works locally but not on host's server
My ISP has set up a directory for me with 'write' permissions. I can successfully have an aspx page create and save a text file to this directory. When I try to use the built-in .NET 2.0 file upload component I don't get an exception but the file is not successfully uploaded. Any ideas as to what's going on?  The site is most likely in medium trust. I don't know much about trust levels. Could this be the problem?   can you show us the code. Also chekc if the directory path provided in the ISP is correct ?Vikram www.vikramlakhotia.comPlease mark the answer if i...

How to make the form View save it's field values in Visual Stdio .NET
Hi every one .this's my first post in this forum ,hope you can help me ..i have this problem ,i have a form View that i use to insert data into a data base ,the thing is: i want the text values inserted in the Text Fields in the Insert Template in The Form View to be saved ,meaning that when the insert operation completes these text field still contain the text values that was inserted in ..note : i tryed to enable the view State in those TextBoxes but that didn't work ..  I think it's about SqlDataSource Refreshing  the FormView or Some thing like that ,but i don'...

Smart Device Application for file transfer to a remote server in .Net Compact Framework (Using Visual Studio.Net 2003,C# code)
Dear all, We are developing a smart device application (using C# code) for .Net Compact Framework where we need to write a programme in C# code to transfer a file from mobile device to remote server/machine.Can anyony help us regarding this aaplication.If you have already done this or you find any article/link regarding to this application then please let me know about that. My mail id : anirbandas.ju@gmail.com Looking forward for your reply soon. Regards Anirban   hi hav u got any solution , becoz i too need. plz share with me...

Loading Visual Studio.net 2003 on a pc with Visual Studio.net 2005 installed
I have recently installed Visual Studio.net 2005 on a pc and have been using it to create a .net 2.0 application. I also have pc running Visual Studio 2003 that I use to support a .net 1.1 application. This pc has broke. Would I be ok loading Visual Studio 2003 on the machine I have running Visual Studio 2005 so I can manage both the .net 1.1 and the .net 2.0 applications?               Thanks Danny Hmmm. Not sure if it works in that direction, but I installed VS2005 on a machine that has VS2003 already installed and they se...

ADO.NET Programming in Visual Basic .NET
Has anyone read "ADO.NET Programming in Visual Basic .NET, Second Edition" by Steve Holzner (Author), Bob Howell (Author)? I am trying to working on a project and there are a few things that I need to tie up quickly in my web forms. Is this book a good one? karls------------------------------------'Old and wrinkled is not what I expected to become when I grew up!'...

Installing .NET 2 causes 'server application anunavailable' on existing .NET 1.1 site
Hi!I have a computer running an ASP.NET 1.1 web site. After installing .net framework 2.0 on the same server I got a 'server application anunavailable' on the ASP1.1 web site. I set the Security settings to 'Everyone' and I temporarily solved the problem.What should I do?Dimitris PapadimitriouSoftware Development Professional If you are running on Windows 2003, they you need to make sure that your V1.1 and V2.0 applications are running in a separate application pool/process.  Otherwise, you will get a load error when the second CLR gets loaded into the same process. Try going into th...

SQL Server Reporting Services for SQL SERVER 2000 AND Visual Studio.NET 2005 .NET 2.0
Hi, Which version of SQl Server Reporting Services will work with SQL SERVER 2000 in pararrel with ASP.NET 2.0 (.NET 2.0 framework)?  Thanks, Azam HighOnCodingWanna get high! Hi, Okay I got the answer. Yes, we can use the SQL SERVER 2005 Reporting Services with SQL SERVER 2000. HighOnCodingWanna get high! ...

Web resources about - Saving a file from the server on to user's PC. - asp.net.visual-basic.net

Resources last updated: 12/4/2015 10:47:36 PM