save image from fileupload - c#

I am using fileupload control to have image on the form and that that image has to be saved on some folder in hard disk say "E:\\asp_net".
Is there any possible way to save image on disk from fileupload and if there is any other image with same name, it should be overwritten?

Why do you need to save the file in your machine's E drive?
Your ultimate option should be in your Application Folder. It should be like...
FileUpload1.SaveAs(Server.MapPath("~/AppFolderName/" + FileName));

You're looking for the cunningly-named SaveAs method.

following videos cover for your needs;
http://www.asp.net/general/videos/how-do-i-simple-file-uploads-in-aspnet
http://www.asp.net/general/videos/how-do-i-multiple-file-uploads-in-aspnet-1
http://www.asp.net/general/videos/how-do-i-multiple-file-uploads-in-aspnet-2

var filename = Path.Combine(#"E:\asp_net", myFileUploadControl.FileName);
if (File.Exists(filename))
File.Delete(filename);
myFileUploadControl.SaveAs(filename);

Related

How to load image from file into picturebox using C# windows form using Microsoft Visual Studio

I have some problem regarding to my project. I'm using C# windows form using Microsoft Visual Studio.
Can anyone help me how to load image from file into picturebox? I have 300++ on image folder.
The system can search by work no., empl no. or name on text box. Then after user typing and click enter on the textbox, the employee details with image appears on the picture box.
All the image is name according to their work no.
The information details is retrieve from database but image from folder. Can anyone help me please :)
pictureBox1.Image = Image.FromFile(#"your image file path");
you can use a OpenFileDialog to get the file path
Here you go:
PictureBox1.Image = Image.FromFile(#"C:\MyPict.jpg");
In response to your code posted in the comment, give this a try:
const string imageFolderPath = #"C:\photo\";
var imageName = textBoxWorkNo.Text;
var fullImagePath = imageFolderPath + imageName + ".jpg";
if (File.Exists(fullImagePath))
pictureBox1.Image = Image.FromFile(fullImagePath);
else MessageBox.Show("File not exist");

pre-visualize an image

I'd like to pre-visualize an image in a image box before save it in a directory.
How can i do this, i use a checkbox to see if the user wants to pre-visualize or not because i dont find another way to do this without a checkbox.
I use file upload to upload the image.
string serverFileName = "";
serverFileName = Path.GetFileName(Upload.PostedFile.FileName);
Upload.PostedFile.SaveAs(MapPath("~/fotosPerfil/") + serverFileName);
i use this piece of code to save the image.
I think this post is exactly what you need to implement. Check out Ivan's solution.
Yes, indeed you can read the path selected by the user and display the image in an <img> tag, all client-side prior to uploading.

i want to save a image with out user interaction in C#

I m scanning image in a form i want to save the image with out user interaction in C# can any one help..
string chktemp = #"C:\"+pic+".tif";
Bitmap bm= new Bitmap(from file);//Here it is asking already saved file with out this i want to save just now scanned image from form
bm.Save(chktemp);
Use IO to check if the current file exists, and if so delete it first.
See: System.IO documentation
File.Exists
http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx
File.Delete
http://msdn.microsoft.com/en-us/library/system.io.file.delete.aspx
Load the Image File to Stream ,than you can Create Bitmap from Stream ,which will close the File Read Operation in source Image .

C sharp Text to jpg - how to change image extension

I am using following code to convert text to jpg on the fly.
context.Response.ContentType = "image/jpeg";
SaveAsJpeg(bitmap, context.Response.OutputStream, (long)100);
When I display the page on the internet images look fine on the surface. But when I right click and save image as or save page as, I get ashx as file extension.
How can I get jpg as file extension?
context.Response.AddHeader("Content-Disposition", "attachment; filename=your-name-here.jpg");
This tells the browser what name the file should be saved as.

Resource file modification date

I am getting an image from a resource file like this:
Image img = (Image)Resources.ResourceManager.GetObject(imgName) as Image;
Is there a way to get the modification date of this image?
Sorry, you won't be able to access that information as the image is loaded into the assembly as binary information, not as a file.

Categories