p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > .NET > Other .NET > General .NET
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 6th, 2007, 01:09 PM
Registered User
 
Join Date: Aug 2007
Location: Jaipur, , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default fileupload control in formview insert item templat

hi Friends..

I am new to asp.net2.o world & trying my hands here & there,
when trying i find utility of using server controls in formview
very useful.now the problem is this that when i tried to use
fileupload control in formview insert item template, that is
not working, i am trying to upload a image file in my data folder
as well as in data table. my data type for images is varchar.
i have tried it lot in net but no success plz help me,if u
can give me full code or method of solving my problem
thank you friends

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old August 6th, 2007, 01:20 PM
Friend of Wrox
Points: 512, Level: 8
Points: 512, Level: 8 Points: 512, Level: 8 Points: 512, Level: 8
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

First of all, datatype of image cannot be varchar. I think it should be image. Or, you can store the path of image file in database table. For uploading the file in some folder on server, use following code:

FileUpload1.PostedFile.SaveAs("C:\\FolderName"); // you should preferably use relative path here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old August 6th, 2007, 01:27 PM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

For a detailed description of both options that gaurav_jain2403 gave, take a look here:
http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=414

Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old August 6th, 2007, 01:43 PM
Registered User
 
Join Date: Aug 2007
Location: Jaipur, , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi gaurav,
first of all thanks to reply.
i have made a database table in sql where with other string
items like name address etc, i have used a varchar datatype
for my images & store data in jpg format like abc.jpg
now when i am using a formview to see data in item template
i dragged a imageweb control in formview & binded it to
image(varchar) field of my database it is working fine
up to this point ,but now in inseritem template i am using
a file uploader control to upload file the only binding properties
it is showing is enable & visible. , thatswhy i am not able
to bind the file upload control to image field.i have not used
any code for file uploader
if you think that this method is wrong can you tell me another method
to do it i know that i am asking too much but i would greatfull
to you.if u tell me preferably in c#
thankyou

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old August 6th, 2007, 01:55 PM
Registered User
 
Join Date: Aug 2007
Location: Jaipur, , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi imar
now the link which u have given is fine with fileuploader
outside the formview , but would it work in inserttemplate
of form also & if yes than how & what i should write at
my form page

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old August 6th, 2007, 02:06 PM
Registered User
 
Join Date: Aug 2007
Location: Jaipur, , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

my code in html page is like this & no C# code


        <asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="Code"
            DataSourceID="SqlDataSource1" Style="z-index: 100; left: 32px; position: absolute;
            top: 88px" Height="368px" Width="560px" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" GridLines="Both" OnItemInserted="FormView1_ItemInserted" OnItemUpdated="FormView1_ItemUpdated" OnItemDeleted="FormView1_ItemDeleted">
            <EditItemTemplate>
                <h1>
                    <span style="font-size: 16pt">Edit Item.....</span></h1>
                Code: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;
                <asp:Label ID="CodeLabel1" runat="server" Text='<%# Eval("Code") %>'></asp:Label><br />
                <br />
                Name: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>'>
                </asp:TextBox><br />
                <br />
                Price: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>'>
                </asp:TextBox><br />
                <br />
                Description: &nbsp; &nbsp; &nbsp; &nbsp;<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'>
                </asp:TextBox><br />
                <br />
                FileThumb:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 120px; position: absolute;
                    top: 264px" Text='<%# Bind("FileThumb") %>'></asp:TextBox>
                <br />
                <br />
                FileZoom:&nbsp;
                <asp:TextBox ID="TextBox2" runat="server" Style="z-index: 101; left: 120px; position: absolute;
                    top: 304px" Text='<%# Bind("FileZoom") %>'></asp:TextBox>
                &nbsp; &nbsp;&nbsp;
                <br />
                <asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("FileThumb", "Images/ChildrenImages/Thumbs/{0}") %>'
                    Style="z-index: 103; left: 416px; position: absolute; top: 136px" />
                <br />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                    Text="Update">
                </asp:LinkButton>
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel">
                </asp:LinkButton>
            </EditItemTemplate>
            <InsertItemTemplate>
                <h1>
                    <span style="font-size: 16pt">Insert Item....</span></h1>
                <br />
                Name: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>'>
                </asp:TextBox><br />
                <br />
                Price: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>'>
                </asp:TextBox><br />
                <br />
                Description: &nbsp;&nbsp; &nbsp;<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>'>
                </asp:TextBox><br />
                <br />
                FileThumb: &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
                <asp:FileUpload ID="FileUpload1" runat="server" Style="z-index: 100; left: 104px;
                    position: absolute; top: 240px" Enabled="true" Visible='<%# Eval("FileThumb") %>' />
                &nbsp;
                <br />
                <br />
                FileZoom: &nbsp; &nbsp; &nbsp;&nbsp;
                <asp:TextBox ID="FileZoomTextBox" runat="server" Text='<%# Bind("FileZoom") %>'>
                </asp:TextBox><br />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                    Text="Insert">
                </asp:LinkButton>
                <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel">
                </asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
                <h1>
                    <span style="font-size: 16pt">Product Description.......</span></h1>
                Code:
                <asp:Label ID="CodeLabel" runat="server" Text='<%# Eval("Code") %>'></asp:Label><br />
                <br />
                Name:
                <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>'></asp:Label><br />
                <br />
                Price:
                <asp:Label ID="PriceLabel" runat="server" Text='<%# Bind("Price") %>'></asp:Label><br />
                <br />
                Description:
                <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>'>
                </asp:Label><br />
                <br />
                <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("FileThumb", "Images/ChildrenImages/Thumbs/{0}") %>'
                    Style="z-index: 100; left: 352px; position: absolute; top: 112px" />
                &nbsp;
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                    Text="Edit">
                </asp:LinkButton>
                <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                    Text="Delete">
                </asp:LinkButton>
                <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                    Text="New">
                </asp:LinkButton>
            </ItemTemplate>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
        </asp:FormView>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old August 6th, 2007, 02:23 PM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Hi rakuntal,

My article mainly helps you with writing the code for saving and retrieving files from the database.

To mix those concepts with controls like the FormView, you need to look into some basic Data Control Tutorials:

http://quickstarts.asp.net/QuickStar...a/default.aspx
http://msdn2.microsoft.com/en-us/lib...inserting.aspx

In particular, search Google for more information about handling the ItemInserting and ItemUpdating events. Inside these events, you can use FindControl to find the file upload control and work from there.

Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old August 6th, 2007, 02:28 PM
Friend of Wrox
Points: 512, Level: 8
Points: 512, Level: 8 Points: 512, Level: 8 Points: 512, Level: 8
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

I have not worked with FormView. But can give you the idea. Add commandArgument=<%# Bind('DataTableID') %> to linkbutton "InsertButton". when this button is clicked and file for that corresponding row is browsed, write this code in FormView1_ItemInserting(not FormView1_ItemInserted):

string arg = e.CommandArgument.ToString();
// arg will contain the Id from the database for corresponding row

if (FileUpload1.PostedFile != null)
{
FileUpload1.Postedfile.saveAs("FilePath");
// or if you want to save the file in database, write code here
// insert the data in the row with Id equal to e.CommandArgument.ToString() in database
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old August 6th, 2007, 02:30 PM
Friend of Wrox
Points: 512, Level: 8
Points: 512, Level: 8 Points: 512, Level: 8 Points: 512, Level: 8
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Imar, your previous article for saving and retrieving files from the database was great.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old August 6th, 2007, 02:34 PM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Thank you..... ;)

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access denied error when using FileUpload Control mii2029 ASP.NET 3.5 Basics 0 October 25th, 2008 06:45 PM
Problem to implement CSSClas on fileupload control azizur123 ASP.NET 2.0 Professional 1 October 13th, 2008 10:50 AM
FileUpload control aliirfan84 ASP.NET 2.0 Professional 1 June 2nd, 2007 04:37 PM
FileUpload Control MunishBhatia ASP.NET 2.0 Basics 2 December 6th, 2006 04:03 AM
FileUpload control -- file size detection ekwong ASP.NET 2.0 Basics 3 November 7th, 2006 06:32 PM



All times are GMT -4. The time now is 03:00 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc