(FileUpload)FormView1.FindControl(FileUpload1).FileName

D

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).FileName 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)
{
fileOK = true;
}
}
}

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

Garfilone

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
 
D

Dave

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


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)FormView1.FindControl(FileUpload1).FileName 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)
{
fileOK = true;
}
}
}

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

Dave

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


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)FormView1.FindControl(FileUpload1).FileName 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)
{
fileOK = true;
}
}
}

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

treefort.jesse

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



Wow...you totally lost me on that one. :-s
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).FileName 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)
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+
(FileUpload)FormView1.FindControl(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top