Users of my web site will be able to upload a picture. This picture will land in /images/folder/picture.jpg. The question I have is: When running under VS2008, a form will insert a full row in a database column (sql server)and the picture will be uploaded to the folder. The result page will show the image. But when running the web server again later, the database will be ok but the image won't be there anymore since I guess that the local server each timer starts freshly with no content in the folder. I am new to uploading so I am wondering how you do to test this kind of thing.
Also, must the folder for the images be under /Content ? I am not sure where to put it and how it will transition when running under IIS ?
Thx
The ASP.NET development server does not clear the directory each time it starts. Have you verified the files are actually being written where you think they are? Seems like you've probably got some path issues and the files are possibly being written to the ASP.NET Temporary Files folder which may change from instance to instance.
I've have to test this with my local server to see exactly what it's doing with regard to the image that's being uploaded locally... but one thought is that instead of storing the picture on the file system, store it in the database itself.
Related
I know it's been asked and I have read the posts and Googled this all day. Still nowhere near something that works. Using an .aspx page, I need to upload a .pdf file to a specific website. I'm doing development using VS2017 and VB.Net. The app will run on different websites. It needs to upload client files to a specific different website and path. Also, the file name of the uploaded file will not be the same as the local source file. Creating the new name is no problem.
Let's say a local file must be uploaded to a website at https://www.appfileserver.co.za/pdfdocs, but I'm on https://www.myownsite.com. So, when using FileUpload1.SaveAs(rootedpath) the path that goes in there must be the rooted path to the target. What would the rooted path look like for the example I provided?
FYI, I know the IP addresses, http paths and anything else I need to know because I control those sites. It would be great to do an FTP upload. I have done this many times from desktop apps. Unfortunately I'd need the full path to the local file. It seems there is no way a web page is allowed to get that full path, so FTP upload is out - or is there a way?
After battling for two days trying to FTP upload from website to website (which is not possible because server firewalls block this), I finally solved it. The solution was a simple one. I deployed the upload .aspx file on the target server then embedded that in an iframe on the client machine apps. The files are then uploaded one time to the right place. Simple and 100% effective. Hopefully somebody see's this and understands it - so as to avoid the troubles I had.
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.
I have created a website let's name it a.com. Now in this website (a.com) the users can upload an image that gets saved to a folder on remote server and the path is getting saved to database.
There is a second website (b.com) which has been hosted on the same server where the image needs to be retrieved.
Can we do this? If yes then please suggest some solution
Language Used = Asp.net 4.0 C#
Backend = SQL2008
It cane be done, if both website can access the remote folder. You need to use something like System.Net.WebClient to download image from remote server.
Since your using SQL and .Net im going to assume your using IIS aswell,
Creating a Virtual directory is probably your best bet, Easy to setup, easy to manage and Extremely handy to understand (if not vital)
http://www.iis.net/learn/get-started/planning-your-iis-architecture/understanding-sites-applications-and-virtual-directories-on-iis
This is assuming you want to display the image in b.com, if you simply want to retrieve it you can do so by retrieving the path and using the image in any other way, you may need to set permissions on the image folder.
first of all both sites should use the same database to share information about images.
If I understand correctly b.com and the files are on the same server. If so put folder's virtual path to configuration.
After that, check database for new records. If found one, parse the name of the file and find it on the server.
As an example you get an image on a.com and insert it on database as
name="image.jpg"
b.com checks database for new records and finds image.jpg.
b.com reads configuration and finds
path="http://c.com/"
combines path and imagename
fulllink="http://c.com/image.jpg"
I've a classified ads system on ASP.NET/c#/MS SQL, and I'm trying to figure out where to store the images that people upload when placing an ad. The ad itself is being stored in a SQL server database.
The images are now being stored in a subfolder of my webapp. It seems to work fine, however I only recently discovered a big problem. Everytime a user deletes an ad, the attached images are to be deleted as well including the folder they reside in. This leads to a restart of the asp.net application. I searched internet and found that restarting the web-app is actually intended behaviour when a subfolder is being deleted.
Obviously, I need to fix this. But how to do that? Where can I store images in such a way that:
I can remove these images including the folders they are stored in?
I can acces them using a URL (the images need to be shown in the
webpages)
Without getting the web-app being
restarted?
Any feedback is appreciated!
Paul
See this question Deleting a directory results in application restart
An other alternative would be to store the images in the DB instead.
Another option would be to put the images in a directory completely unrelated to the web site then serve the images through a scripted page or handler. It would make all of your image urls look like mydomaincom/serveimage.aspx?imageid=323422, but unless you're counting on the name somewhere that really shouldn't matter much. Obviously it would require a modification to the page that serves the images in the first place as well, but if sub directories of this unrelated directory are deleted IIS really shouldn't care at all.
maybe you can store the images in SQL (check at the filestream feature in this case)
if not, I suppose you have somewhere in a business facade class, a service class or wherever you want, a methode "DeleteAd".
This method will have to do two things :
-delete the sql data
-delete the file image
also, you may change the image store to another folder, outside the web app. You will probably end with writing a custom handler (myhandler.ashx?fileid=XX) to serve the files, or a custom route and control if you use MVC.
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.