(FileUpload)FormView1.FindControl(FileUpload1).FileName

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    (FileUpload)FormView1.FindControl(FileUpload1).FileName

    If you had a FileUpload control inside of a FormView...how would you
    use FindControl to access the FileUpload properties? Let me just say
    that (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName doesn't
    work.

    The purpose is to insert a graphic in the InsertItemTempl ate section of
    the form. I'm using the expample that's in the online help for the
    post back.

    protected void Page_Load(objec t sender, EventArgs e)
    {
    Profile.UserID = User.Identity.N ame;
    if (IsPostBack)
    {
    Boolean fileOK = false;
    String path = Server.MapPath( "~/images/entry/");
    if
    ((FileUpload)Fo rmView1.Row.Fin dControl(FileUp load1).HasFile)
    {
    String fileExtension =

    System.IO.Path. GetExtension((F ileUpload)FormV iew1.Row.FindCo ntrol(FileUploa d1.FileName)).T oLower();
    String[] allowedExtensio ns =
    { ".gif", ".png", ".jpeg", ".jpg" };
    for (int i = 0; i < allowedExtensio ns.Length; i++)
    {
    if (fileExtension == allowedExtensio ns[i])
    {
    fileOK = true;
    }
    }
    }

    if (fileOK)
    {
    try
    {
    FileUpload1.Pos tedFile.SaveAs( path
    +
    (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName);
    Label1.Text = "File uploaded!";
    }
    catch (Exception ex)
    {
    Label1.Text = "File could not be uploaded.";
    }
    }
    else
    {
    Label1.Text = "Cannot accept files of this type.";
    }
    }
    }


    If there's a better way to do this...I'm open for suggestions. I would
    still like to know the trick behind the FindContol issue though.

    Thanks

  • Garfilone

    #2
    Re: (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName

    FindControl() method just returns a handle of the control to you,and
    you have to new a same-type instance referring to the control on the
    page.You can modify your code & try

    GOod Luck :-)

    Dave ¼g¹D¡G
    If you had a FileUpload control inside of a FormView...how would you
    use FindControl to access the FileUpload properties? Let me just say
    that (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName doesn't
    work.
    >
    The purpose is to insert a graphic in the InsertItemTempl ate section of
    the form. I'm using the expample that's in the online help for the
    post back.
    >
    protected void Page_Load(objec t sender, EventArgs e)
    {
    Profile.UserID = User.Identity.N ame;
    if (IsPostBack)
    {
    Boolean fileOK = false;
    String path = Server.MapPath( "~/images/entry/");
    if
    ((FileUpload)Fo rmView1.Row.Fin dControl(FileUp load1).HasFile)
    {
    String fileExtension =
    >
    System.IO.Path. GetExtension((F ileUpload)FormV iew1.Row.FindCo ntrol(FileUploa d1.FileName)).T oLower();
    String[] allowedExtensio ns =
    { ".gif", ".png", ".jpeg", ".jpg" };
    for (int i = 0; i < allowedExtensio ns.Length; i++)
    {
    if (fileExtension == allowedExtensio ns[i])
    {
    fileOK = true;
    }
    }
    }
    >
    if (fileOK)
    {
    try
    {
    FileUpload1.Pos tedFile.SaveAs( path
    +
    (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName);
    Label1.Text = "File uploaded!";
    }
    catch (Exception ex)
    {
    Label1.Text = "File could not be uploaded.";
    }
    }
    else
    {
    Label1.Text = "Cannot accept files of this type.";
    }
    }
    }
    >
    >
    If there's a better way to do this...I'm open for suggestions. I would
    still like to know the trick behind the FindContol issue though.

    Thanks

    Comment

    • Dave

      #3
      Re: (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName

      Wow...you totally lost me on that one. :-s



      Garfilone wrote:
      FindControl() method just returns a handle of the control to you,and
      you have to new a same-type instance referring to the control on the
      page.You can modify your code & try
      >
      GOod Luck :-)
      >
      Dave ¼g¹D¡G
      >
      If you had a FileUpload control inside of a FormView...how would you
      use FindControl to access the FileUpload properties? Let me just say
      that (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName doesn't
      work.

      The purpose is to insert a graphic in the InsertItemTempl ate section of
      the form. I'm using the expample that's in the online help for the
      post back.

      protected void Page_Load(objec t sender, EventArgs e)
      {
      Profile.UserID = User.Identity.N ame;
      if (IsPostBack)
      {
      Boolean fileOK = false;
      String path = Server.MapPath( "~/images/entry/");
      if
      ((FileUpload)Fo rmView1.Row.Fin dControl(FileUp load1).HasFile)
      {
      String fileExtension =

      System.IO.Path. GetExtension((F ileUpload)FormV iew1.Row.FindCo ntrol(FileUploa d1.FileName)).T oLower();
      String[] allowedExtensio ns =
      { ".gif", ".png", ".jpeg", ".jpg" };
      for (int i = 0; i < allowedExtensio ns.Length; i++)
      {
      if (fileExtension == allowedExtensio ns[i])
      {
      fileOK = true;
      }
      }
      }

      if (fileOK)
      {
      try
      {
      FileUpload1.Pos tedFile.SaveAs( path
      +
      (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName);
      Label1.Text = "File uploaded!";
      }
      catch (Exception ex)
      {
      Label1.Text = "File could not be uploaded.";
      }
      }
      else
      {
      Label1.Text = "Cannot accept files of this type.";
      }
      }
      }


      If there's a better way to do this...I'm open for suggestions. I would
      still like to know the trick behind the FindContol issue though.

      Thanks

      Comment

      • Dave

        #4
        Re: (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName

        Wow...you totally lost me on that one. :-s



        Garfilone wrote:
        FindControl() method just returns a handle of the control to you,and
        you have to new a same-type instance referring to the control on the
        page.You can modify your code & try
        >
        GOod Luck :-)
        >
        Dave ¼g¹D¡G
        >
        If you had a FileUpload control inside of a FormView...how would you
        use FindControl to access the FileUpload properties? Let me just say
        that (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName doesn't
        work.

        The purpose is to insert a graphic in the InsertItemTempl ate section of
        the form. I'm using the expample that's in the online help for the
        post back.

        protected void Page_Load(objec t sender, EventArgs e)
        {
        Profile.UserID = User.Identity.N ame;
        if (IsPostBack)
        {
        Boolean fileOK = false;
        String path = Server.MapPath( "~/images/entry/");
        if
        ((FileUpload)Fo rmView1.Row.Fin dControl(FileUp load1).HasFile)
        {
        String fileExtension =

        System.IO.Path. GetExtension((F ileUpload)FormV iew1.Row.FindCo ntrol(FileUploa d1.FileName)).T oLower();
        String[] allowedExtensio ns =
        { ".gif", ".png", ".jpeg", ".jpg" };
        for (int i = 0; i < allowedExtensio ns.Length; i++)
        {
        if (fileExtension == allowedExtensio ns[i])
        {
        fileOK = true;
        }
        }
        }

        if (fileOK)
        {
        try
        {
        FileUpload1.Pos tedFile.SaveAs( path
        +
        (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName);
        Label1.Text = "File uploaded!";
        }
        catch (Exception ex)
        {
        Label1.Text = "File could not be uploaded.";
        }
        }
        else
        {
        Label1.Text = "Cannot accept files of this type.";
        }
        }
        }


        If there's a better way to do this...I'm open for suggestions. I would
        still like to know the trick behind the FindContol issue though.

        Thanks

        Comment

        • treefort.jesse@gmail.com

          #5
          Re: (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName

          I am in the middle of the exact same situation. did you find any
          resolution here?
          --
          Jesse Gavin



          On Nov 19, 6:13 am, "Dave" <KillnComput... @Verizon.Netwro te:
          Wow...you totally lost me on that one. :-s
          >
          Garfilone wrote:
          FindControl() method just returns a handle of the control to you,and
          you have to new a same-type instance referring to the control on the
          page.You can modify your code & try
          >
          GOod Luck :-)
          >
          Dave 寫道:
          >
          If you had a FileUpload control inside of a FormView...how would you
          use FindControl to access the FileUpload properties? Let me just say
          that (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName doesn't
          work.
          >
          The purpose is to insert a graphic in the InsertItemTempl ate section of
          the form. I'm using the expample that's in the online help for the
          post back.
          >
          protected void Page_Load(objec t sender, EventArgs e)
          {
          Profile.UserID = User.Identity.N ame;
          if (IsPostBack)
          {
          Boolean fileOK = false;
          String path = Server.MapPath( "~/images/entry/");
          if
          ((FileUpload)Fo rmView1.Row.Fin dControl(FileUp load1).HasFile)
          {
          String fileExtension =
          >
          System.IO.Path. GetExtension((F ileUpload)FormV iew1.Row.FindCo ntrol(FileUploa d1.FileName)).T oLower();
          String[] allowedExtensio ns =
          { ".gif", ".png", ".jpeg", ".jpg" };
          for (int i = 0; i < allowedExtensio ns.Length; i++)
          {
          if (fileExtension == allowedExtensio ns[i])
          {
          fileOK = true;
          }
          }
          }
          >
          if (fileOK)
          {
          try
          {
          FileUpload1.Pos tedFile.SaveAs( path
          +
          (FileUpload)For mView1.FindCont rol(FileUpload1 ).FileName);
          Label1.Text = "File uploaded!";
          }
          catch (Exception ex)
          {
          Label1.Text = "File could not be uploaded.";
          }
          }
          else
          {
          Label1.Text = "Cannot accept files of this type..";
          }
          }
          }
          >
          If there's a better way to do this...I'm open for suggestions. I would
          still like to know the trick behind the FindContol issue though.
          Thanks

          Comment

          Working...