By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,972 Members | 1,383 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,972 IT Pros & Developers. It's quick & easy.

(FileUpload)FormView1.FindControl(FileUpload1).Fil eName

P: n/a
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)FormView1.FindControl(FileUpload1).Fil eName doesn't
work.

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

protected void Page_Load(object sender, EventArgs e)
{
Profile.UserID = User.Identity.Name;
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath("~/images/entry/");
if
((FileUpload)FormView1.Row.FindControl(FileUpload1 ).HasFile)
{
String fileExtension =

System.IO.Path.GetExtension((FileUpload)FormView1. Row.FindControl(FileUpload1.FileName)).ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}

if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+
(FileUpload)FormView1.FindControl(FileUpload1).Fil eName);
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

Nov 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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 gDG
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)FormView1.FindControl(FileUpload1).Fil eName doesn't
work.

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

protected void Page_Load(object sender, EventArgs e)
{
Profile.UserID = User.Identity.Name;
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath("~/images/entry/");
if
((FileUpload)FormView1.Row.FindControl(FileUpload1 ).HasFile)
{
String fileExtension =

System.IO.Path.GetExtension((FileUpload)FormView1. Row.FindControl(FileUpload1.FileName)).ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}

if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+
(FileUpload)FormView1.FindControl(FileUpload1).Fil eName);
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
Nov 19 '06 #2

P: n/a
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 gDG
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)FormView1.FindControl(FileUpload1).Fil eName doesn't
work.

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

protected void Page_Load(object sender, EventArgs e)
{
Profile.UserID = User.Identity.Name;
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath("~/images/entry/");
if
((FileUpload)FormView1.Row.FindControl(FileUpload1 ).HasFile)
{
String fileExtension =

System.IO.Path.GetExtension((FileUpload)FormView1. Row.FindControl(FileUpload1.FileName)).ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}

if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+
(FileUpload)FormView1.FindControl(FileUpload1).Fil eName);
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
Nov 19 '06 #3

P: n/a
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 gDG
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)FormView1.FindControl(FileUpload1).Fil eName doesn't
work.

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

protected void Page_Load(object sender, EventArgs e)
{
Profile.UserID = User.Identity.Name;
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath("~/images/entry/");
if
((FileUpload)FormView1.Row.FindControl(FileUpload1 ).HasFile)
{
String fileExtension =

System.IO.Path.GetExtension((FileUpload)FormView1. Row.FindControl(FileUpload1.FileName)).ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}

if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+
(FileUpload)FormView1.FindControl(FileUpload1).Fil eName);
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
Nov 19 '06 #4

P: n/a
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.Netwrote:
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)FormView1.FindControl(FileUpload1).Fil eName doesn't
work.
The purpose is to insert a graphic in the InsertItemTemplate section of
the form. I'm using the expample that's in the online help for the
post back.
protected void Page_Load(object sender, EventArgs e)
{
Profile.UserID = User.Identity.Name;
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath("~/images/entry/");
if
((FileUpload)FormView1.Row.FindControl(FileUpload1 ).HasFile)
{
String fileExtension =
System.IO.Path.GetExtension((FileUpload)FormView1. Row.FindControl(FileUpload1.FileName)).ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+
(FileUpload)FormView1.FindControl(FileUpload1).Fil eName);
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
Nov 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.