473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
4 5650
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jens Jensen | last post by:
Hello, I have an image file name in a table that a let users modify via a GridView/DetailView pair. * The actual image file is saved in the image folder of the application. But the image is...
1
by: Bob | last post by:
I've made an upload function saving to a specific folder and dropdownlist reading and listing files from the folder. When I upload, the list is rendered a second time in the dropdownlist with the...
0
by: sandya | last post by:
here is the code i tried string ss; //FileUpload FileUpload1 = new FileUpload(); Label Labeltxt = new Label(); //FileUpload1 = FormView1.FindControl("FileUpLoad1") as FileUpload; FileUpload...
0
by: Christian Schlemmer | last post by:
If my code will run into the filesize-limit condition, the INSERT-statement will be executed. is there a way to avoid that? Protected Sub DetailsView1_RowInserting(ByVal sender As Object,...
6
by: Chris | last post by:
I want do my insert to a database using a formview bound to an objectdatasource. I also want to upload a file. I'm quite new to and this is just test code but Is there any way I can pass the file...
0
by: RosH | last post by:
Dear All, Please find below an Inserting Event code expected to trigger just before the insert event of a FormView control. Everything works just fine but the event throws an exception that the...
9
by: vital | last post by:
Hi, I have a User control which has a fileupload control. With the requirements I placed the user control in a UpdatePanel of ASP.NET Ajax and the fileupload.postedfile.filename giving error. ...
2
by: =?Utf-8?B?UGF1bA==?= | last post by:
I have a gridview with 2 columns. One column is a BoundColumn to a part number (string). One column is an ItemTemplate with a FileUpload control. There can be multiple rows (i.e. part numbers)...
4
by: imruler | last post by:
guys i have a html form that has action to redirect it to asp page,, dat asp page has vb script that recieves values from the form and add it to access db..out of those i hav two textboxes for which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.