How to auto-upload files to a server from a local directory in ASP.NET - asp.net

I am trying to upload an image from my computer to hosting server using ASP.NET code, but I don't know if it's possible.
If it is, can you help me?

Sure it's possible. Read up on how the FileUpload class works: https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.fileupload?view=netframework-4.8
It won't be an automatic upload like you ask in the title, but you will be able to send files thru the browser and wherever you want them to go.

Related

ASP.Net Accessing Server Filesystem

I am having trouble accessing information on the server my website it on. As the website was originally programmed with VB.Net, I cannot change the language without having to completely reboot the website. The way the website and server are configured, I can only use ASP.Net and VB.Net.
I am needing to add a section where they can create folders, edit folder names, and upload pictures and text documents on the server through the public website. I tried using parts of the FileIO, Server, and Http that should have worked, but none of them did. Most of my research is about local files and text documents.
I have not been able to find any information that works. Can someone help me? Thank you.
Firstly, creating a virtual directory in ISS mapped to somewhere on your disk would be a good start. This way you have a separate folder for user data in a folder with write access (make sure IIS has write access to the folder!), and the folder is not affected by website deployments.
Secondly, you might need to resolve absolute path for most of the System.IO.File calls. See How to convert a relative path to an absolute path in a Windows application?, just you will need to convert this code to VB.

Upload file to server using class dll

It is fairly easy to upload a file using web form. But I need to accomplish this through DLL.
I have classic ASP page with file upload form and I need to create an object that handles the uploaded file from customer and save the file to the server. What would be the best way to approach this? I have been digging and came across Web.HttpPostedFile and HttpWebRequest. but I don't know which route to take.
Also, I am a bit confused about how to pass the uploaded file to DLL so my class can upload and manipulate the file. is there any sample code for this?
Thanks for any help or advice.
This question doesn't make much sense, as you kind of asking "I have old car's parts and I need to assemble one by using a wheel". What? That doesn't make sense.
A dll is a container for some code. You do not use a container per se to upload a file. You should search for "classic asp upload file sample", find a solution, give it a try and come back with a specific problem.
I also noticed HTTPS tag, the idea with S, is that you don't care whether it is secure or not from the programming perspective. If you are able to use HTTP, it is trivial to upload files to HTTPS - just change the URL in the UI. The server code itself wouldn't change. What will change is the server hosting configuration, you would have to add certificate details.

Access to dynamic images on server

I'm developing a web application in which users uploads images and I'm keeping the location of the uploaded image path on server. For example:
C:\fix_directory\a8531.jpg
In my page, I want to display this image but I couldn't. I've tried many things but couldn't find a way of doing it.. This directory isn't part of my project because it will be always updated.
What is the effective way of overcoming this problem?
Thank you
You could setup a virtual directory (yourweb.com/images) which points to your images, or even a web (cdn.yourweb.com).
You could also write a HTTP handler or a file handler (.ashx) in ASP.NET to serve your images from that location.
Update
I guess the most effective way of overcoming this problem would be to store the uploaded files simply somewhere in your web directory.
Update 2
I'm definitley sure, the most effective way of overcoming this problem is to have a real IIS or a Visual Studio Development Server and not trying to do anything with the Vista Home Basic pseudo IIS which can do nothing.
The simplest way would be to make fix_directory a virtual directory within your project inside of IIS, and access the images that way.
A more complex approach would be to do something in the lines of pulling in your image via a FileStream, and outputting it to your website via a ResponseStream.
A common way this is achieved is by creating a generic handler (.ashx) that's only responsibility is to output your images.

Physical Path for image saving. Asp.net

I have a web project and I saved my images in Physical folders in hdd Like d:\SecretImages\Imagename. But I can't open the files when I have to?
I thought if it can saves for examle d:\SecretImages\Temp.jpg, I can open when I have to but, I can't.
Help me please, thanks
You cannot use file paths to show your images. The browser doesn't know where to find the images and the server wouldn't serve them up anyway due to security concerns.
You could/should use an HttpHandler to show the images.
I answered a similar question here on SO how to do this.
its becus when iis get file, it get as ASP.NET user not local system user. just go to the folder and add IIS_IURS group to permission list. or just set folder accessible by everyone.
this type of problem mostly not occur when local debugging. but will happen in production or network storage.
Try this article
http://www.aspsnippets.com/Articles/Display-Images-in-GridView-Control-using-the-path-stored-in-SQL-Server-database.aspx

upload file to server in a particular path

In Flex i want to upload a particular file to server form local system.how to do it?
Thanks.
You cannot upload a file without using FileReference.browse() followed by an upload(). If it was possible, that would mean that a webpage can read any file from the user's machine without his knowledge or consent.
Can you even imagine the consequences of that?
You can upload byteArrays though if you are sending some images or texts. http://developer.amazonwebservices.com/connect/thread.jspa?messageID=76422

Resources