Save file into server using openfiledialog

Posted by Oswaldlily under ASP.NET on 5/8/2013 | Points: 10 | Views : 1240 | Status : [Member] | Replies : 3
Following for FileUploadControl
string filename = Path.GetFileName(xfuppt.PostedFile.FileName); // extracting FileName
xfuppt.SaveAs(Server.MapPath("~/Powerpoints/" + filename));

How to do the same for Openfiledialog..using saveas




Responses

Posted by: Raj.Trivedi on: 5/8/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello

First drag and drop a button on Windows Form and a File Dialog Control
and a Label

now on the button click write this code

private void xbrowsebtn_Click(object sender, EventArgs e)
{
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Select file to be upload";
fDialog.Filter = "JPG Files|*.jpg";
if (fDialog.ShowDialog() == DialogResult.OK)
{
lblpath.Text = fDialog.FileName.ToString(); // this will store the path from where the file is being taken.
}
}

Now drag and drop a Button and name it as Upload
and on its click we wil write these code.

private void xupload_Click(object sender, EventArgs e)
{

string path;
string fname = "\\"+YourFileName+ ".jpg";
path = Application.StartupPath;
System.IO.File.Copy(lblpath.Text, path + fname);
path = path + fname;
// now insert the path into database by writing your insert query

}


Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 5/9/2013 [Member] Starter | Points: 25

Up
0
Down
@Raj.Trivedi
From this Application.startuppath ,
now I need to download that file...

how to request path...


Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 5/9/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello

Drag and drop Picture box

On Download button

create a dataset and get the Path of the image that is stored in the database.


pbStudentpic.Image = Image.FromFile(Yourdataset.Tables[0].Rows[0]["YourImagePath"].ToString());

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response