i have two pages:
1st page... let it be adminfileupload page
2nd page... home page(this will be site home page)
i have one folder in solution explorer named images.
what i want to do is adminfileupload has one fileupload control and a button named update when any one browse image file with file upload and click the button(update) then the image should be viewed in home page and also saved in images folder. each time we chose a file and click the button(update) 开发者_高级运维the image should be changed. and this image should be background image, i mean i also have to show some data from database over that image.
working in c# asp.net
Do you need to keep the other pictures too?
If not, you could just upload a picture give it a fix name, Then in the home page you could just set the background image the path to the picture and the fix name. If you have trouble overloading the picture(does not write over you should delete the picture first).But this is a simple approach and depending on the browser you test on it might keep the first picture in their temp file.
If you want to keep the other images you need to do some extra work and have a storing mechanism that will keep track of your pictures or a dynamic variable that changes the path of the resources. I sugest you take a look at the ASP.NET Personal Web Site Starter Kit It has a mechanism that implement a random picture on the first page but the pages are stored in sql database.
Happy coding
The best way I can think of to do this is on the button upload click event, store the file to the server folder. At the same time assign a Session variable the name of the file uploaded.
You will need to manage file names that get stored on the server or check if they already exist, or if different users upload the same file name, etc.
So Session("myImage") = currFileUploaded
Then do a Redirect back to the current page to show the image, which will link to the session variable that just stored the file name that was uploaded.
You'll need to check for a post back and hide or show the image as necessary.
精彩评论