Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
isi19388
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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,588
1 OriginalGriff 528
2 Manas Bhardwaj 383
3 Damith Weerasinghe 330
4 Tadit Dash 315
0 Sergey Alexandrovich Kryukov 9,575
1 OriginalGriff 6,006
2 Peter Leow 4,500
3 Maciej Los 3,540
4 Abhinav S 3,513


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid