how to open a file and save it local

T

ton

Hi

In my app I create an file. I want the user to save this file on the loca
drive (c:\temp). Once saved the user can open Word and use this file as a
merge file so a letter can be generated.

How can this be doen with ASP (vb2005) & javascript

thanx

ton
 
G

Guest

Hi

In my app I create an file. I want the user to save this file on the loca
drive (c:\temp). Once saved the user can open Word and use this file as a
merge file so a letter can be generated.

How can this be doen with ASP (vb2005) & javascript

thanx

ton

You can't save it like this but you can open it directly on the client
and then user can save it in Word

Try to test

Response.Buffer=true;
Response.ContentType = "application/vnd.ms-word";
Response.AddHeader("Content-Disposition",
"attachment;Filename=document.doc");
Response.Write("some text");
Response.Flush();
Response.End();

It should show a popup message to Save/Open the file

Hope this helps
 
T

ThatsIT.net.au

What type of file a word doc?

create a ashx page (Generic handler) not a aspx page, something like this



Imports System.Web
Imports System.Web.Services

Public Class word
Implements System.Web.IHttpHandler

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

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

End Sub

ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class
 
T

ThatsIT.net.au

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")
 
T

ton

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")
 
T

ThatsIT.net.au

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

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?

Using ASHX means you should link to that file from your page. When
user clicked on that link the file will be opened. So you need to add
a hyperlink

<a href="file.ashx">Click to open Word</a>
 
T

ton

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")
 
T

ThatsIT.net.au

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?

you have all ready saved it on the server?

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

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")
 
T

ton

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")
 
T

ThatsIT.net.au

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")
 
T

ThatsIT.net.au

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")
 
T

ton

I 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")
 
T

ton

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")
 
T

ton

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")
 
T

ThatsIT.net.au

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")
 
T

ton

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")
 
T

ThatsIT.net.au

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

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

I think that you have to describe your idea in more details. I don't
get what does "merge Word file and generate letter" means. What
letter, an email? What does Word do then there, an attachment? Can you
send a plain-text email (no attachments) and where from the email must
be sent, from client computer?
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top