Created
November 26, 2015 21:34
-
-
Save shammelburg/322056d777e9975fedde to your computer and use it in GitHub Desktop.
Download File from Server using Web API and AngularJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will download the file from the server | |
// Pass in the filepath of where file is stored and a new file name | |
private static void GetFileFromServer(string currentFilePath, string newFileName) | |
{ | |
HttpResponse httpresponse = HttpContext.Current.Response; | |
httpresponse.Clear(); | |
httpresponse.Charset = "utf-8"; | |
httpresponse.ContentType = "application/pdf"; // mime type to suit file type | |
httpresponse.AddHeader("content-disposition", string.Format("attachment; filename={0}", newFileName)); | |
httpresponse.BinaryWrite(File.ReadAllBytes(currentFilePath)); | |
httpresponse.End(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will open the file in the browser | |
window.open('api/Controller/GetFileFromServer', '_self', ''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment