Save file dialog in asp.net

K

Kapil

Hi All
can u tell me how to save dynamically generated file in asp.net.
like save file dialog in asp.net.

kapil
 
V

Viktor Jevdokimov

Before sending file:
1. Response.ContentType = "application/octet-stream" (or content type of
your file).
2. Response.AppendHeader("content-disposition", "attachment;filename=" &
strFileName)
 
Joined
Dec 20, 2009
Messages
1
Reaction score
0
dialog is not open ??!!!

Hi,
my code for test dialog box:

html:

<body>
<input type="text" id="textToSave"/>
<input type="button" id="saveTxt" onclick="saveText()" />

</body>

javascript:
<script src="js/lib/prototype.js" type="text/javascript" ></script>

<script type="text/javascript">
function saveText() {

new Ajax.Request("api/saveData.cs", {
parameters: { q: "saveText", },
onSuccess: function(request) {

document.getElementById('textToSave').value = "return";
},
onFailure: function(request) {},
onException: function(exception) {}
});
}
</script>

saveData.cs:

public class saveData : IHttpHandler
{
public bool IsReusable { get { return true; } }

public void ProcessRequest(HttpContext c)
{
c.Response.Cache.SetNoStore();
c.Response.AddHeader("Content-Type", "application/x-javascript");

if (c.Request.Form["q"] == null) return;

switch (c.Request.Form["q"])
{
c.Response.ContentType = "application/ms-excel";
c.Response.AddHeader("content-disposition", "attachment; filename=test.xls");
c.Response.TransmitFile(c.Server.MapPath("../files/test.xls"));
//c.Response.Flush();
c.Response.End();

}

}

}

I have tried with flush and without , I also tried it on txt and jpg files.
The dialog box is not opened.

What am I doing wronge????:damnmate:
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top