Have the following code under IIS/ASP, with Chrome browser under Windows:
Response.ContentType = "application/exe"; //also tried application/octet-stream
Response.AddHeader("content-disposition", "attachment;filename=MyFile.exe");
Response.TransmitFile(Server.MapPath("~/MyFile.exe"));
However when I complete the download, the file I downloaded is a different size to the original (the downloaded file is larger), and the digital sig is missing. How do I fix?
This seems to do the trick:
FileInfo info = new FileInfo(Server.MapPath("~/MyFile.exe"));
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-length", info.Length.ToString());
Response.AddHeader("content-disposition", "attachment;filename=MyFile.exe");
Response.TransmitFile(Server.MapPath("~/MyFile.exe"));
Related
As the title says.
I set the values in java like this:
response.setHeader("Content-Disposition", "attachment; filename=" + targetName);
response.setContentType("application/octet-stream");
response.setCharacterEncoding("UTF-8");
I debugged in chrome explorer, and the response body is:
Question solved by changing the submit method in JS file.
At first I send request by this:
Ext.Ajax.request({
utl:'',
params:{},
method:'POST'
});
Butajax can't download a file but can receive json/html/js/string format body.
So in extjs, if you want to download file, DO NOT USE ajax request.
And maybe you'll need use native javascript to do it.
For example:
var form = document.createElement("form);
form.method='POST';
form.action='/';
//deal with data
document.body.appendChild(form);
form.submit();
I wrote a simple asp.net page that simulates file download response. I added the following lines to adjust response:
Response.AddHeader("ETag", "\"" + _EncodedData + "\"");
Response.AddHeader("Last-Modified", lastUpdateTiemStamp);
Response.AddHeader("Accept-Ranges", "bytes");
//Set the ContentType
Response.ContentType = "application/octet-stream";
//Add the file name and attachment,
//which will force the open/cancel/save dialog to show, to the header
Response.AddHeader("Content-Disposition", "attachment;filename=" + dItem.FileName);
//Add the file size into the response header
Response.AddHeader("Content-Length", (endByte - startBytes).ToString());
Response.AddHeader("Connection", "Keep-Alive");
My problem is that Accept-ranges doesn't apear in the response header, but when I change Accept-Ranges to Accept-Ranges1 this header(Accept-Ranges1) will receive a response header.
This problem only occurs when I am debugging the project in Visual Studio. When I am on IIS everything is ok
I'm trying to add a picture to my pdf-file withe the fo:external-graphic-tag:
<fo:external-graphic src="url(resources\common\img\Logo_tiny.png)" />
On my local System everyting works fine, but when i want to run it on the Server-System it says
Image not found. URI: resources\common\img\Logo_tiny.png. (No context info available)
My Fop-Factory-Setup looks like this:
fopFactory.setUserConfig(config);
fopFactory.getFontManager().setFontBaseURL(servletContext.getRealPath("/WEB-INF/config/"));
Fop fop = fopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.MIME_PDF, userAgent, outStream);
Transformer transformer = TransformerFactory.newInstance().newTransformer(transformSource);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(source, res);
// get the pdf:
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=\"Output.pdf\"");
response.setContentLength(outStream.size());
OutputStream responseOutputStream = response.getOutputStream();
outStream.writeTo(responseOutputStream);
responseOutputStream.flush();
responseOutputStream.close();
context.responseComplete();
I checked everything a couple of times: the image is available in the jar-file it is available in the ear-file. The picture is also used in a different context nd there it shows up.
Does anyone have a hint or a solution for this problem?
Many Thanks!!
I wanna to display all the files in a directory in ASP.NET. when i click on the list of files available in that it should get download to local or it should open to view?
How to achieve this ? i got all the files in directory but i don't know to make those files to download?
Thanks in advance.
In order to make the file downlodble you have to add for each file an href
eg
foreach(string fileName in Dir)
{
Response.Write("<a href='"+fileName+"'>file name...</a>");
}
ore you have to force download in such way
public static void ForceDownload(this HttpResponse Response, string virtualPath, string fileName)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.WriteFile(virtualPath);
Response.ContentType = "";
Response.End();
}
One way to do this is to enable directory browsing in IIS.
For whatever reason, directory browsing also displays the web.config file for the directory. The following link discuses how to not show it: http://forums.iis.net/t/1149484.aspx/1
To download mp3 file from 3rd party servers , using general code give
error of need virtual path to download..
using this code :
var fileInfo = new System.IO.FileInfo(filePath);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", filePath));
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.WriteFile(filePath);
Response.End();
error comes that no virtual path set...i repeat i need to download from 3rd party servers with
full url