DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 18 Jun 2007 13:11:02 -0700,    posted on: microsoft.public.dotnet.framework.aspnet.security        back       

Thread Index
  1    Carlos Lozano
          2    Alexey Smirnov
          3    Carlos Lozano


Download file works locally, but not on server - Any idea?   
Hello, 
I have the following section of code in a popup window that is opened from 
other page when clicking a button:
The downloadFile method is called from the Page_Load Event.

private void downloadFile(string filename)
{
               Response.ClearHeaders();
                Response.ClearContent();

                // set the http content type to "APPLICATION/OCTET-STREAM
                Response.ContentType = "APPLICATION/OCTET-STREAM";

                // initialize the http content-disposition header to
                // indicate a file attachment with the default filename
                // "myFile.txt"
                //String disHeader = "Attachment; Filename=\"" + filename + 
"\"";
                string disHeader = "Attachment; Filename=" + filename;
                Response.AppendHeader("Content-Disposition", disHeader);

                // transfer the file byte-by-byte to the response object
                System.IO.FileInfo fileToDownload = new 
System.IO.FileInfo(Server.MapPath("Downloads") + "\\" + filename);            
    
                Response.Flush();
                Response.WriteFile(fileToDownload.FullName);
                Response.End();
}

This code works okay when running locally (http://localhost/site). If I try 
to run it on a server in the internet (http://server/site) it does not show 
the file download dialog. 
The popup window is shown very fast, then it is closed right away.

Any ideas? Is it a security issue?

Thank you,

Carlos
Date:Mon, 18 Jun 2007 13:11:02 -0700   Author:  

Re: Download file works locally, but not on server - Any idea?   
On Jun 18, 10:11 pm, Carlos Lozano
 wrote:

> Hello,
> I have the following section of code in a popup window that is opened from
> other page when clicking a button:
> The downloadFile method is called from the Page_Load Event.
>
> private void downloadFile(string filename)
> {
>                Response.ClearHeaders();
>                 Response.ClearContent();
>
>                 // set the http content type to "APPLICATION/OCTET-STREAM
>                 Response.ContentType = "APPLICATION/OCTET-STREAM";
>
>                 // initialize the http content-disposition header to
>                 // indicate a file attachment with the default filename
>                 // "myFile.txt"
>                 //String disHeader = "Attachment; Filename=\"" + filename +
> "\"";
>                 string disHeader = "Attachment; Filename=" + filename;
>                 Response.AppendHeader("Content-Disposition", disHeader);
>
>                 // transfer the file byte-by-byte to the response object
>                 System.IO.FileInfo fileToDownload = new
> System.IO.FileInfo(Server.MapPath("Downloads") + "\\" + filename);            
>
>                 Response.Flush();
>                 Response.WriteFile(fileToDownload.FullName);
>                 Response.End();
>
> }
>
> This code works okay when running locally (http://localhost/site). If I try
> to run it on a server in the internet (http://server/site) it does not show
> the file download dialog.
> The popup window is shown very fast, then it is closed right away.
>
> Any ideas? Is it a security issue?
>
> Thank you,
>
> Carlos


Try to add a try..catch block to see the error (if any)

try {
....your code
} catch (Exception e)
// file IO errors
{
   Response.Write (e.getMessage());
}

also try to check the path you get in fileToDownload.FullName
Date:Mon, 18 Jun 2007 13:48:00 -0700   Author:  

Re: Download file works locally, but not on server - Any idea?   
That is exactly why I am puzzled. 
The file path is okay and no exception happens. It just does not do what it 
should do when installed on the server. In addition the download page is 
closed automatically, I have not code for closing it. So it is weird.

"Alexey Smirnov" wrote:


> On Jun 18, 10:11 pm, Carlos Lozano
>  wrote:
> > Hello,
> > I have the following section of code in a popup window that is opened from
> > other page when clicking a button:
> > The downloadFile method is called from the Page_Load Event.
> >
> > private void downloadFile(string filename)
> > {
> >                Response.ClearHeaders();
> >                 Response.ClearContent();
> >
> >                 // set the http content type to "APPLICATION/OCTET-STREAM
> >                 Response.ContentType = "APPLICATION/OCTET-STREAM";
> >
> >                 // initialize the http content-disposition header to
> >                 // indicate a file attachment with the default filename
> >                 // "myFile.txt"
> >                 //String disHeader = "Attachment; Filename=\"" + filename +
> > "\"";
> >                 string disHeader = "Attachment; Filename=" + filename;
> >                 Response.AppendHeader("Content-Disposition", disHeader);
> >
> >                 // transfer the file byte-by-byte to the response object
> >                 System.IO.FileInfo fileToDownload = new
> > System.IO.FileInfo(Server.MapPath("Downloads") + "\\" + filename);            
> >
> >                 Response.Flush();
> >                 Response.WriteFile(fileToDownload.FullName);
> >                 Response.End();
> >
> > }
> >
> > This code works okay when running locally (http://localhost/site). If I try
> > to run it on a server in the internet (http://server/site) it does not show
> > the file download dialog.
> > The popup window is shown very fast, then it is closed right away.
> >
> > Any ideas? Is it a security issue?
> >
> > Thank you,
> >
> > Carlos
> 
> Try to add a try..catch block to see the error (if any)
> 
> try {
> ....your code
> } catch (Exception e)
> // file IO errors
> {
>    Response.Write (e.getMessage());
> }
> 
> also try to check the path you get in fileToDownload.FullName
> 
> 
Date:Mon, 18 Jun 2007 14:08:02 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us