How can i fill “Choose File Upload Dialog” programmatically using C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ronio
    New Member
    • Aug 2012
    • 1

    #1

    How can i fill “Choose File Upload Dialog” programmatically using C#

    Im working on a project in which i have to upload a file. I have tried WebHttpRequest class and WebClient class to do this but could not succeed. So, if i programmaticall y fill and click the choose file dialog then it can be done otherwise not. Im using C# for this project.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Are you developing something that runs for a webpage or for windows?
    I do not understand what you are asking?

    Comment

    • Mudassir
      New Member
      • May 2012
      • 85

      #3
      well for uploading files into the database using a file upload lets assume uploading images you can do as follows
      Code:
      if (fuPhoto.HasFile) // fuPhoto is the name of file upload
                      {
                          string path = Server.MapPath("~/profile/");
                          string file = fuPhoto.PostedFile.FileName;
                          fuPhoto.SaveAs(path + file);
                          string[] ext = file.Split('.');
      
                          if (Request.Cookies["ProfilePic"] == null && Request.Cookies["Extension"] == null)
                          {
                              HttpCookie profileCookie = new HttpCookie("ProfilePic");
                              profileCookie.Value = ext[0].ToString() + "." + ext[1].ToString();
                              profileCookie.Expires = DateTime.Now.AddDays(1);
                              Response.Cookies.Add(profileCookie);
      
                              HttpCookie extensionCookie = new HttpCookie("Extension");
                              extensionCookie.Value = ext[1].ToString();
                              extensionCookie.Expires = DateTime.Now.AddDays(1);
                              Response.Cookies.Add(extensionCookie);
                          }
                          else
                          {
                              Response.Cookies["ProfilePic"].Value = ext[0].ToString() + "." + ext[1].ToString();
                              Response.Cookies["Extension"].Value = ext[1].ToString();
                          }
                          if (!ClientScript.IsStartupScriptRegistered("alert"))
                          {
                              ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('File has been uploaded..'); 
                          }
                      }
      now you can save the file by your query into the database..
      ...
      Addan

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Ok so yes you are dealing with a webpage.
        For security reasons, browser do not let you autofill the the values for file uploads.
        You could *TRY* making a customized silverlight control(think activeX or a java applet) for the webpage, but seems a bit exccessive.

        Comment

        • ariful alam
          New Member
          • Jan 2011
          • 185

          #5
          @Mudassir,

          You wrote in first uploading a file in database. but you may be used file system here. isn't it?

          Comment

          Working...