473,440 Members | 1,788 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,440 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 5653
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).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 ¼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).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 ¼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).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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.