kmc10314
asked on
image upload in C#
I'm trying to upload image into SQL server database.
What's important is that i'm not really uploading image itself, but path to the location of the picture
I'll save the picture in designated location (in this case let's say it's c:\images\), and have imageURL
saved like \images\picture1.jpg
I'd like to set a limit so that people don't upload anything but jpg, bmp, gif, png
I'll post up what I have and please help ASAP code.txt code.txt
form.txt
What's important is that i'm not really uploading image itself, but path to the location of the picture
I'll save the picture in designated location (in this case let's say it's c:\images\), and have imageURL
saved like \images\picture1.jpg
I'd like to set a limit so that people don't upload anything but jpg, bmp, gif, png
I'll post up what I have and please help ASAP code.txt code.txt
form.txt
ASKER
this gives me error of
cannot convert system.web.httppostedfile to string
cannot convert system.web.httppostedfile to string
ASKER
well i got that problem fixed, but i still need help with saving a picture to a location like c:\images\
and saving the path as string.
My method does not even store the filename seems to be null
and saving the path as string.
My method does not even store the filename seems to be null
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i did. Problem is now that it's not getting any file even though i upload it.
It does not even show any message
I already uploaded aspx file up there and I'm going to attach code snippet for my behind code.
it seems like the it has no file even though I choose the file.
It does not even show any message
I already uploaded aspx file up there and I'm going to attach code snippet for my behind code.
it seems like the it has no file even though I choose the file.
if (fileUpload.PostedFile.ContentLength > 0)
{
string extension = Path.GetExtension(fileUpload.PostedFile.FileName);
if (extension == ".jpg" || extension == ".jpeg" || extension == ".jpeg" || extension == ".png" || extension == ".bmp" || extension == ".gif")
{
try
{
string fileName = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName);
string savePath = "c:\\images\\";
fileUpload.PostedFile.SaveAs(savePath);
Session["filename"] = fileName;
Response.Write("File Uploaded");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
else
{
Response.Write("Please upload jpg/jpeg, bmp, gif, png file only");
}
}
else
{
Response.Write("You have no file.");
}
ASKER
Now.. I think there is something wrong with this part
try
{
string fileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string savePath = "c:\\images\\";
FileUpload1.PostedFile.SaveAs(savePath);
Session["filename"] = fileName;
Response.Write("File Uploaded");
}
ASKER
when i submit the file i get this error
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
ASKER
priyanath helped me to restrict the extension, but most of part i had to take care of the problem by myself.
if (extension == ".jpg" || extension == ".jpg" || ".bmp" ) // and other types
{
proceed....
}
else
{
show error message
}