Click here to Skip to main content
13,045,540 members (71,588 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi
I currently am running an application in which i need users to be able to upload a file to a directory on the server.

please help
Posted 4-Oct-12 20:55pm
isi19520
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hii, I think it helps to u. It is in C# i hopes u can understand..
if (UploadImage.PostedFile != null)
            {
                string fileName = UploadText.FileName.ToString();
                string[] dots = fileName.Split('.');
                string fileType = "txt";
                string type = dots[dots.Length - 1];
                string type1 = dots[dots.Length - 1];
                if (fileType.IndexOf(type) == -1)
                {
                    UploadText.Focus();
                    return;
                }
                else
                {
                    string UploadDescription = Description.Content;
                    string strUploadPath = "", strFilePath = "";
                    strFilePath = @"C:\\UploadTextFiles\";
                    string path = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Millisecond.ToString();
                    strUploadPath = Server.MapPath(strFilePath) + path + UploadText.FileName;
                    UploadText.PostedFile.SaveAs(strUploadPath);
                    // UploadText.SaveAs(strUploadPath);
 

                    byte[] imageSize = new byte[UploadImage.PostedFile.ContentLength];
                    HttpPostedFile uploadedImage = UploadImage.PostedFile;
                    uploadedImage.InputStream.Read(imageSize, 0, (int)UploadImage.PostedFile.ContentLength);
 
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = @"INSERT INTO table(Cols1,Cols2) VALUES (@UploadImage,@UploadText)";
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = con;
                                      
 
                    SqlParameter UploadedImage = new SqlParameter("@UploadImage", SqlDbType.Image, imageSize.Length);
                    UploadedImage.Value = imageSize;
                    cmd.Parameters.Add(UploadedImage);
 
                    SqlParameter UploadedText = new SqlParameter("@UploadText", SqlDbType.VarChar, 200);
                    UploadedText.Value = strUploadPath;
                    cmd.Parameters.Add(UploadedText);
 
                   
 
                    con.Open();
 
                    int result = cmd.ExecuteNonQuery();
                    con.Close();
                    if (result > 0)
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + strImageName + " image inserted successfully')", true);
                    SqlDataAdapter da = new SqlDataAdapter("select * from UploadProjectDetails", con);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    GridView1.DataSource = ds.Tables[0].DefaultView;
                    GridView1.DataBind();
                }
 
            }
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Add a FileUpload control[^] to your page. The link includes an example that does what you want.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100