how to open a file and save it local

T

ton

ok,

it is working, THANK you. Now I'm trying to let it work for the users, so I want to download 2 files:
- address.txt and after this is done the doc file, where the correct address via merge can be refreshed

download both files is no problem. I have added a panel, were I first show the address.txt file and when this is ready I let them open the doc file. The addres file should be saven on a fixed place (Question: is it possible to set a default place in the proecessrequest sub?)
The doc file should be openen. And here is a new problem. The original filesize was 23.5 kb It is stored on the server, but after downloading is is 28.5 kb
After opening (or saven it and then opening by dbl click). Word will be opened but the user will be prompted to choose the character 9japan, chinees and so on), so the file is changed (bigger). I suppoose it has to do with the "record-size" of the download process but how can this be corrected.

thanx


ton
"ThatsIT.net.au" <me@work> schreef in bericht
no myfile is the ashx file,

The address to the csv file is in the code that goes in the ashx file, line 3 below

but instead of creating the file in the first place why not just send emails straight from the web page?

Or create the link as I showed to the ASHX page. put the code I supplied in it, and it will work, I tested it, it works.


I prefer to use AJAX. My interface is very rich with information about customers and so on. I had the idea that writing a letter to a contact would be easy:
- first i thought using word on the server. this does work but is a violation with the licenseagreement and not stable since office is not a multiuser product.
- my second thougth was juist generate the merge fields in a list, let the user open word and merge this togeter to get the letter. This is not the best solution, but fair enough
- your suggested that I could add :
<a href="myfile.ashx">click here</a>
i presume myfile is the file i have created. But as you suggested a button would also do the trick: the trick is:


context.Response.ContentType = "text/csv"

context.Response.AddHeader("content-disposition", "attachment;filename=yourdoc.csv")

Dim csvFile As IO.FileInfo = New IO.FileInfo(context.Server.MapPath("\yourfolder\yourfile.csv"))

Dim sr As IO.StreamReader = csvFile .OpenText

context.Response.Write(sr.ReadToEnd)

So what I have in mind is the following idea

I add a button outside the updatepanel (next to the templates the user can choose from)

after picking 1, no postback will occur, but on the clientside I will make the button vissible. The text would be GET merge file

I create the merge file on the server and will and with your lines.

I hope it will work. But if you have some better ideas, i would appreciate it



thanx



ton



"ThatsIT.net.au" <me@work> schreef in bericht Better to not use the Ajax.

if you cant give a link to the file, then its not going to work no matter what.

you simply have to allow the user to navagate to it, it does not have to be the same button

all it needs is

<a href="myfile.ashx">click here</a>
when adding these line in an non ajax enviroment it gives the popup dialog to open or save the file. Using it on a button within an updatepanel I get:

sys.webforms.pagerequestmanagerparsererrorexception: the message received from the server could noy be parsed. Common causes for this error are when the rersponse is modified bij calls response.write(), response filters, httpmodules or server trace is enabled. etc

so how about this challenge?

I do not use the ashx file.

any ideas?

thanx

ton


"ton" <[email protected]> schreef in bericht btw it is all running in an ajax updatepanel
have not done it, but I still do not get it where the ashx get involved. The button procedure creates the doc file on the server and then what?

thanx
"ThatsIT.net.au" <me@work> schreef in bericht change path to fiole to suit

replace previous 3 lines of code with





context.Response.ContentType = "text/csv"

context.Response.AddHeader("content-disposition", "attachment;filename=yourdoc.csv")

Dim csvFile As IO.FileInfo = New IO.FileInfo(context.Server.MapPath("\yourfolder\yourfile.csv"))

Dim sr As IO.StreamReader = csvFile .OpenText

context.Response.Write(sr.ReadToEnd)





sorry I did not get straight back as promised I had a long phone call

will give you the code in a minute or 2



what do you mean navigating to the ashx file. The webpage shows information about customer data, with textboxes, dropdownlist, buttons and so on. Pressing on the "sendletter button" creates a csv or text file whatever. It is this file I want to promt to the user so he can save it. After opening word and choosing the correct template this file will be used in the merge.

Other questions are in your message

Thanx
"ThatsIT.net.au" <me@work> schreef in bericht I guess we better make sure were reading from the same page
a few quick questions, ill be watching for your answers so we can move quick

You already have code that creates a txt file? YES

you have all ready saved it on the server? YES

if so what name did you give it, did you save it as blah.csv ? YES

try navigating to the ashx file and tell me what happens


I'm sorry. I do use visual studio and I have added your file. But it is a ASP appllication which after clicking by the users will end in creating the txt file. This file is forst stored on the server but then. What should I do next. I still see no place where and how to use the ashx file


thanx
"ThatsIT.net.au" <me@work> schreef in bericht Are you using visual studio?

if so add a ashx page, called generic handler in the menu


then all you need is to add 3 lines, 5the last line will write you data. ashx page is much like a aspx page but dose not include a load of stuff needed for a web page. its used for displaying other file types such as a csv file


context.Response.ContentType = "text/csv"

context.Response.AddHeader("content-disposition", "attachment;filename=yourdoc.csv")

context.Response.Write("Hello World!")




I do not know what you mean.
Your suggestion is that I should add a file to my solution (ashx): I did this and then?

<%@ WebHandler Language="VB" Class="word" %>

Imports System

Imports System.Web

Public Class word : Implements IHttpHandler


Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

context.Response.ContentType = "text/csv"

context.Response.AddHeader("content-disposition", "attachment;filename=yourdoc.csv")

context.Response.Write("Hello World!")

End Sub


Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable

Get

Return False

End Get

End Property

End Class

What should I do with it?

thanx
"ThatsIT.net.au" <me@work> schreef in bericht change

context.Response.ContentType = "application/msword"
context.Response.AddHeader("content-disposition", attachment;filename=yourdoc.doc")

to

context.Response.ContentType = "text/csv"
context.Response.AddHeader("content-disposition", attachment;filename=yourdoc.csv")
 
G

Guest

the same problem the file is now 29 kb in stead of 23 kb
context.Response.ContentType = "application/vnd.ms-word "

Try to make

Response.Clear

before you output to the browser
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top