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
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