Click here to Skip to main content
16,012,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i trying to do a file upload, i want to image to save to image folder (a folder create in the project),
however, the image don't know appear in the directory that i indicate

if i show all file, it appear there, so i click on that image and include it in the project,however,
it shouldnt be the case that i everytime upload an image, i need to redo that again

so how should i allow it to always appear when i upload a image?

this is my code
C#
protected void uploadImage()
{
	string filename = FileUploadImg.FileName;
	string fileType = filename.Substring(filename.Length - 4).ToLower();
	if ((fileType == ".gif") | (fileType == ".jpg") | (fileType == ".png")) {
		FileUploadImg.SaveAs("C:\\Users\\Jane\\Desktop\\project\\FileUpload\\FileUpload\\WebRole1\\images\\" + txtboxName.Text + "_" + FileUploadImg.FileName);
	} else {
		Interaction.MsgBox("failed");

	}
}

<img src="http://i286.photobucket.com/albums/ll115/cutexxbaby/blank.jpg" border="0" alt="Photobucket">
Posted
Updated 6-Jan-12 21:19pm
v3

1 solution

Not a good idea - to automatically include it in your project, you would have to edit the relevant .csproj file and / or trhe resx file. While these are in XML and are perfectly readable, I do not know what effect direct modification will have on VS - it may not notice, it may complain. Personally, I wouldn't do it. Save them well away from your project, and add them manually.
 
Share this answer
 
Comments
cutexxbaby 7-Jan-12 4:28am    
but i need it for a function call upload, where user upload the photo and later on the photo will be use by a image control
OriginalGriff 7-Jan-12 4:42am    
I think we are talking at cross purposes here.
Go back a stage.
You have a file upload control.
The user loads it, and presses the "upload" button.
What exactly to you want to happen?
cutexxbaby 7-Jan-12 8:52am    
when i click on upload control, user will select the image that they want to upload, when i click on "upload" button, it should save my image to the folder call "images" that i have created in the project
OriginalGriff 7-Jan-12 10:07am    
OK. When you are working with web projects, do not hard-code paths. Use a relative path, or a path starting with a backslash, and convert it to an absolute path using the Server.MapPath method instead:
FileUploadImg.SaveAs(Server.MapPath("/Images/" + filename));
You should also make sure there is a file first, using the FileUpload.HasFile property.
This code should not be in a method that you normally call though - it should be in the FileUpload Button Click event.
cutexxbaby 8-Jan-12 8:15am    
can show me what to do? the code? in order for upload to work...but what wrong with my code ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900