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 1

Add a FileUpload control[^] to your page. The link includes an example that does what you want.
  Permalink  
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

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

  Print Answers RSS
0 Dnyaneshwar@Pune 1,300
1 Sergey Alexandrovich Kryukov 802
2 Tadit Dash 305
3 ravikhoda 300
4 OriginalGriff 292
0 Sergey Alexandrovich Kryukov 11,441
1 OriginalGriff 6,930
2 Peter Leow 4,850
3 Abhinav S 3,838
4 Maciej Los 3,575


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