Is there a public URL to view the file content on CodePlex? - codeplex

My new project is at https://test.codeplex.com . I have checked in a file called test.txt . Is there a public URL that I can download/view the test.txt directly from a web browser ?
Previously with Google Code I could always do that with something like http://test.googlecode.com/svn/trunk/test.txt

Related

ASP.Net Mvc - Physical location (e.g. on C:\ drive) of OutputCacheLocation.Client files

I have a frequently-visited page which contains a number of images. I would like to download the image to the client's machine on the first occasion that the image is requested, and, refer to that file on subsequent requests, rather than download again.
To set this up, I have the following Mvc action:
[OutputCache(Duration = 3600, Location = OutputCacheLocation.Client, VaryByParam = "id")]
public async Task<ActionResult> Download(string id)
{
DigitalMedia returnItem = await GrabFile(id);
return File(returnItem.FileData, returnItem.MIMEType, returnItem.FileName);
}
I'm trying to test out if my code is actually downloading the images, so I'd like to physically view them on my machine as they are downloaded.
Can anyone let me know where this physical location is? I am using Windows 7 and IE10, and have been observing files appearing in the following location, but I'm not really sure what I should be looking for:
C:\Users\MyName\AppData\Local\Microsoft\Windows\Temporary Internet Files
The actual img tag containing the request to download is rendered as follows, so I was hoping to see a file with a name such as 0000000001-0000000000000400922 somewhere on my machine, but I can't see one.
<img class="xsyco-map" alt="slide" src="/DigitalMedia/Download/0000000001-0000000000000400922"/>
I have looked at the following similar threads, but haven't found a reply
ASP.NET MVC - caching pages on client side
MVC caching database images
Thanks

Allow direct access to some file/content in Asp.Net MVC

In my Asp.Net MVC application, I am using a customized template of twitter bootstrap.
I have placed this template folder named "b3-detail-admin" on root of my mvc application.
Using Browser's address bar, when I am trying to access one file directly from this folder like so:
http://my-pc/MyWebAppMvc/b3-detail-admin/font/fontawesome-webfont.woff
I am getting following error:
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
What should I do to have direct access to all files/folders under "b3-detail-admin" folder?
In mvc you can only get access to the routes defined in RouteConfig.
You can add a ActionResult which returns the document like so:
public ActionResult GetPdf()
{
string file = Server.MapPath("~/folder/file.pdf");
return File(file, "application/pdf", "file.pdf");
}
You then can make it dynamic to get all sorts of files:
public ActionResult GetFile(string url, string mime)
{
string file = Server.MapPath(url);
string filename = url.Split(new char[]{'/'})[url.Split(new char[]{'/'}).Count()];
return File(file, "mime", filename);
}

How to show a pdf file in the browser tab from an action method

I'm trying to do pdf viewer functionality in mvc application. When user click the "read the pdf" link it should open a new tab/window and user should be able view the pdf file. So I checked the examples but I couldn't find. Could you suggest me any article or example ?
Show an anchor tag in your first view and pass an id (to identify what PDF to show)
#Html.ActionLink("read the pdf","view","doc",new { #id=123},null)
Now in the doc controller, have an action method which have a parameter called id and return the pdf there using the File method.
public ActionResult View(int id)
{
byte[] byteArrayOfFile=GetFieInByteArrayFormatFromId(id);
return File(byteArrayOfFile,"application/pdf");
}
Assuming GetFileInByteArrayFormatFromId is the method which returns the byte array format of the PDF file.
You can also return the PDF if you know the full path to the PDF file physically stored, using this overload.
public ActionResult Show()
{
string path="FullPAthTosomePDFfile.pdf";
return File(path, "application/pdf","someFriendlyName.pdf");
}
Show the PDF in a browser without downloading it
Based on the browser setting of the end user, the above solution will either ask user whether he/she wishes to download or open the file or simply download/open the file. If you prefer to show the file content directly in the browser without it gets downloaded to the user's computer, you may send a filestream to the browser.
public ActionResult Show(int id)
{
// to do : Using the id passed in,build the path to your pdf file
var pathToTheFile=Server.MapPath("~/Content/Downloads/sampleFile.pdf");
var fileStream = new FileStream(pathToTheFile,
FileMode.Open,
FileAccess.Read
);
return new FileStreamResult(fileStream, "application/pdf");
}
The above code expects you to have a pdf file named sampleFile.pdf in ~/Content/Downloads/ location. If you store the file(s) with a different name/naming convention, you may update the code to build the unique file name/path from the Id passed in.
If you want to display the PDF Content in browser, you can use iTextShare dll.
Refer the link http://www.codeproject.com/Tips/387327/Convert-PDF-file-content-into-string-using-Csharp.
Reading PDF content with itextsharp dll in VB.NET or C#

ASP.NET MVC open pdf file in new window

I have a MVC application. I need to open the pdf file when user clicks the open button on the page. The filepath where the pdf is stored is read from the database and it is a file on c:. How do I open it in my html code? I have this code:
Open
but this doesn't open my file. What do I have to do? I need to specify somewhere that it is a pdf??
You will need to provide a path to an action that will receive a filename, resolve the full path, and then stream the file on disk from the server to the client. Clients out in the web, thankfully, cannot read files directly off your server's file system (unless... are you suggesting #Model.CertificatePath is the path to the file on the remote user's machine?).
public ActionResult Download(string fileName)
{
string path = Path.Combine(#"C:\path\to\files", fileName);
return File(path, "application/pdf");
}
Update
If #Model.CertificatePath is the location on the client's actual machine, try:
Open
Note that some browsers may have security settings disallowing you from opening local files.
Try like this in your View
#Html.ActionLink("View", "ViewPDF", new { target = "_blank" })
Now Link will open in new window. You can write the pdf bytes in ViewPDF controller method
You could have the link fire a method such as the one below which will then stream your chosen file to the file download rather than opening the pdf in the broswer.
/// <summary>
/// Forces a file to be displayed to the user for download.
/// </summary>
/// <param name="virtualPath"></param>
/// <param name="fileName"></param>
public static void ForceDownload(string virtualPath, string fileName)
{
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.AddHeader("content-disposition", "attachment; filename=" + fileName);
response.WriteFile(virtualPath);
response.ContentType = "";
response.End();
}
Well if your getting the path value and the value is in #Model.CertificatePath
this wiil not work
Open
You will need to add this
Open
and make sure you path is relative by adding this ~
for example if your path is /Content/pdfs/CertificatePath.pdf
it would need to look like
~/Content/pdfs/CertificatePath.pdf
This should be the simplest way to make it work.
Hope this helps.
Unfortunately you can't dictate where the PDF will be opened, mainly because you can't guarantee the Adobe Acrobat reader plugin is installed or how it functions.
You could in theory open a new window, and in that new window have a JavaScript function to open the PDF file, but again you can't guarantee it will open in a embedded window without the plugin, the best you can hope for is "best try".

Using ASP.NET MVC, can I download a file using a jQuery GET and FilePathResult?

My app needs to download a file after the file has been cached and then download the file. I have one jQuery.post() cache the file and then call the following after the file is successfully cached:
<script type="text/javascript">
function startViewingFiles(fileNames) {
$.get(
'<%= Url.Action(MvcTemplates.Document.DisplayDownload()) %>',
{ fileName: fileNames[0] },
function() {
$('<div class="status fill"><p>Download complete</p></div>')
.appendTo('#ViewerContainer')
.fadeIn('slow');
}
);
}
</script>
This communicates with the following action, as I have observed the calls actually make it to the server in VS 2008 and the FilePathResult exits the method successfully:
[HttpGet]
public virtual ActionResult DisplayDownload(string fileName)
{
var path = _CacheService.GetCachedPath(fileName);
return new FilePathResult(path, _MimeDictionary.LookupMimeType(fileName));
}
Using Firebug, I see the response contains a "500 Internal Server Error" that complains of a System.UnauthorizedAccessException: Access to the path 'C:\websites\WebSubscriptionPortal\CacheLocation' is denied. I configured both the VS development server and the web app in IIS 7.5 to run as my user with full access to the directory, but I always get this error. When I have the view output WindowsIdentity.GetCurrent().Name, it outputs my user name regardless of which server I use.
Why am I getting the UnauthorizedAccessException?
Apparently, I cannot use jQuery to download a file using FilePathResult. Is this true?
Do I need to change the method used on the client or the ActionResult on the server to start the download via a Javascript method?
Update: The UnauthorizedAccessException exception is due the fact that the fileNames parameter is null, as no route was setup to map to a method with a parameter named "fileNames". So the path parameter to the FilePathResult constructor is simply the directory name as shown in the exception message.
No. You cannot use jQuery to return a file via download. You can, however, set location.href to the action that delivers the file and it will download it without changing the current page. This assumes that the FileResult is an attachment, which it typically is. You should change the method on the client to use location.href instead of jQuery get. I'm not sure why you are getting the access exception. It could be that while you have access to the particular directory, your account doesn't have access to one of the intervening directories in the path.

Resources