In my project i will be having an link like
Download
I want the users to download files of different types. The file will be in the root folder. When i am clicking on the link it is displaying an error. This is the plugin to install in the chrome. If the user download this link and open then it will automatically add to the chrome.
How can i do this.
The file is not even downloading.
This isn't a valid path:
~/hello world.crx
The ~ character is for use server-side to denote the root of the application. Client-side it has no meaning. The browser doesn't know what the root of the application is (or what the application is at all), it's just sending requests to resources at addresses. And it doesn't know what to do with that address.
You'll need to either use some server-side logic to translate that path into a browser-useable path, or manually make it a relative or absolute path.
If the ASP.NET MVC Framework isn't translating this for you then you're probably using a version that requires a little more manual work for it. Try something like:
Download
(Note: This assumes the use of the Razor view engine. If you're not using that then you'll want to use whatever your view engine equivalent is.)
What you need to do is set up a directory online, where you can host the file.
I also see that in your aref you don't want to type the full path so denote it with a /hello_world.crx, but make sure that you've set up a base href:
<base href="http://yourdomain.com/something/">
Try renaming the file to remove any spaces e.g. "hello_world.crx" and then change the name in the link code to match.
if a webpage and the downloadable file is in the same location
(i.e)
SampleFolder->Download.html
SampleFolder->hello world.crx
then try the below
download
If the webpage and the downloadable file in different location
(i.e)
SampleFolder->Download.html
SampleFolder->Downloads->hello world.crx
then try the below
download
Related
I have the following structure:
AppName
Content
img
file.png
I can navigate directly to mysite.com/Content/img/file.png without any issues.
However when I add test.txt to img and set to Copy Always and type Content (same as file.png), I get No webpage was found for the web address when visiting the link, when I want to be able to enable folks to download the publicly accessible file (no auth needed), just like the image. Why isn't this working?
I can see test.txt in the bin folder of the app. Does something else need to be configured to enable direct file downloads?
Make sure your IIS site settings or web.config have mime type associated with .txt extension.
https://www.iis.net/configreference/system.webserver/staticcontent/mimemap
i just wanna upload afile from a fixed path, so i dont want browse button, I need just a TextBox(Path of my file some thing like c:/junk/upload) and and upload button.some thing like
[TextBox.Path][UploadButton]
or can i get the code in java applets or any other lanaguage?
For security reasons, a webpage loaded in a browser from internet cannot directly refer the local file system. You need a desktop application or plugin to achieve this.
no we can make using asp.net or java applets and yes what you said is right, security reasons! , but every applications has a sand box limits and thats include file handling as default , and we achived that. with out problem
I'm building an application which involves writing some fields to a database, along with uploading some files from the end user to an FTP site. The file upload works fine... in IE. In Firefox and Chrome, I get an error that it can't find the file (running it in localhost at this point, haven't moved it to a dev or production environment yet).
I have tried getting the file via:
Server.MapPath(FileUpload1.PostedFile.Filename)
... which points to the folder the application is residing in.
And also:
Path.GetFullPath(FileUpload1.PostedFile.Filename)
... which points to c://Programs (x86)/... ...
I can get a file to upload properly if I get it from either folder, but nothing from anywhere else.
Any ideas on how to make this point to the right place? Or, will it actually work properly once it resides in a server environment?
Thanks in advance!
FileUpload.PostedFile.Filename works differently in each browser. in Firefox and Chrome it won't include the full path - just the file name. It depends on your customer's browser.
FileUpload.PostedFile.FileName
This actually gives you path of the uploaded file.
But in all the newer browsers (FF 3.6 series, Chrome, IE7+) this feature has been disabled due to security reasons. Any website should not need path of a file stored in client's systems because that gives the directory structure and may expose other important things to website owner.
So in your case, the above code returned only the file name.
you can check this link, it may help you Fileupload control - fullpath issue
Is there any way to show user popup to give the name to create folder
And with that if he does not want to create folder then he should be shown the list of folders to which he want to save the file
Is it proper way that I create a popup with javascript with the list of folders on my server and put a textbox and button to save the new and in code we will create directory in code passed with textbox?
string pathToCreate = "~/UserFolders/" + TextBox1.Text;
if(Directory.Exists(Server.MapPath(pathToCreate))
{
//In here, start looping and modify the path to create to add a number
//until you get the value needed
}
//Now you know it is ok, create it
Directory.CreateDirectory(Server.MapPath(pathToCreate));
string targetPath = Server.MapPath("FolderName"); //with complete path
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
fileToUpload.PostedFile.SaveAs(targetPath + ImageFileName);
}
else
{
fileToUpload.PostedFile.SaveAs(targetPath + ImageFileName);
}
As I mentioned by commenting that Functionality like SaveFileDialog is only possible in Windows Forms application, you cannot do this in asp.net
The alternatives in asp.net are difficult however as an alternate there is a third party editor available on the web called CKEditor 3.x Developer's Guide.
You can use File Browser (Uploader) for the purpose you want to achieve.
to create folder :
System.IO.Directory.CreateDirectory(newPath);//newpath is your folder creating path
If you are developing web applications (I can see you have tagged your question as asp.net), you do not need to worry about the pop up window. You just send the file through the Response and the download window will be shown by the browser.
Using the Example given in How to Create a Folder or File You can create a folder, but in asp.net you can not Use open file dialog or save file dialog functionalities, this will work only in C# Windows forms application.
Web applications and the HTTP protocol do not support direct manipulation of the server-side file system. In fact, that would be a dangerous idea.
It sounds like you have a base folder somewhere on the web server where you want users to be able to upload files, with some user control over subfolders and location of the uploaded file. I would suggest dong this by presenting the file system in a tree view or a list of links (where the links let you navigate up/down the folder tree). Combine this with a file input and you've got yourself a solution. HOWEVER, be very careful to control and cleanse the specified file name for the uploaded file. There are many combinations (such as utilizing "..") that can allow the user to hack into unwanted file locations on your server.
How do I reference a file outside my web site's root directory?
For example my website is located at C:\dev\TestSite
I am using ASP.NET with XSP. The webapp will be deployed on Apache using mod_mono.
I have images in C:\images and I would like to do this:
<img src="C:\images\logo.gif"/>
Your img tag's src value is going to be sent to the client. You need to specify those paths relative to your document root. Your best bet is to set up a virtual folder (in IIS, alias is the apache equivalent) to point to the c:\images path and then change the mentioned tag src path as follows
<img src="/images/logo.gif" />
To do this in apache, you need an alias in your httpd.conf. The line looks like this
Alias /images c:/images
Here's the docs http://httpd.apache.org/docs/2.0/mod/mod_alias.html#alias
While it might be possible to do this through some hacky method, it's not a good idea. Allowing the IIS account to access files/folders on the greater file system would be a big potential security hole.
The best way to accomplish this is to use IIS Virtual Directories. Put your content in folders dedicated to supporting the site, DO NOT make your entire C: drive a virtual directory.
I'm going to assume that C:\images\logo.gif is the path on the server, and not the path on the client.
The src attribute is interpreted by the html client (i.e. Internet Explorer). The client can't see anything outside of your web directory. In fact, the client can only see things inside your web directory if you've provided permission for them to do so. Thus, this isn't an ASP.NET issue, but an issue of how web clients have access to web servers... which is designed this way for security.
In order for your application to use these images, you've got a couple of options that immediately spring to mind - neither of which is ideal:
The ASP.NET code (in the codebehind) is going to need to go and grab the file, and serve it out in the html stream that is being served to the client, which is more a complex task than I suspect you are willing to embark on.
The ASP.NET code (using System.IO) is going to need to go and grab the file from it's home location in C:\images\logo.gif and copy it to a location that is accessible to the client - you could create a temporary directory, copy your image to it, serve it out, delete it, delete the directory.
Both of these are certainly hacks that should be avoided if possible, but if you're adamant that this is what you want to do, this will allow you to do it via your ASP.NET app.
The most ideal solution is to add C:\Images as a virtual directory to your document root, i.e. /ImageCentral - this way you can have images that are central to multiple websites stored in this directory, it can then be referenced by clients for any of the websites just by adding virtual directories to each of them pointing at the central images folder. As DaveSwersky points out, don't make any directories containing sensitive information virtual directories, the minute you add a virtual directory to an externally visible website, you're giving people free reign to any of the information in it.
Good luck
You can't do this from within the HTML code of your page. The HTML page can only reference web accessible content (in regards to images, CSS, javascript, etc). You could create a virtual directory that points to your images folder so that it becomes web accessible.
EDIT:
The apache way inside of your conf file.
Alias /images "C:/Images"
And a little walkthrough from some dude.