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