Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2009, 11:56 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile deleting items from physical folder

Hello sir,
The almost last thing I am struggling with is that I am trying to delete the contents from physical folder. When a "delete" query is fired from any of the data bound controls, it deletes the record from database but leaves out the stuff in physical folder as trash which will never be used again.
I have idea about deleting/renaming files/folders, but I am having problem in getting the exact Id of the file while deleting. I am using FormView. How I get the exact Id of item.
My page is AddDeleteSong.aspx which contains the FormView. How the id of item can be acquired?
I am using following code snippet.

Code:
Private con As New SqlConnection("server=.\SqlExpress;AttachDbFileName=|DataDirectory|Gallery.mdf;Integrated Security=True;User Instance=True")
Private fileNamePath As String
Then files are being uploaded properly(except files are duplicated in the physical folder)

Code:
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
        Try
            
            Dim theFileUpload As FileUpload = CType( _
                            FormView1.FindControl("FileUpload1"), FileUpload)
            If theFileUpload.HasFile Then
                fileNamePath = "~/Music/" & Guid.NewGuid.ToString()
                Dim theExtension As String = Path.GetExtension(theFileUpload.FileName)
                fileNamePath &= theExtension
                theFileUpload.SaveAs(Server.MapPath(fileNamePath))
                
                e.Values("SongPath") = fileNamePath
                e.Values("SongExtn") = theExtension
                
            End If
        Catch ex As Exception
            Throw
        End Try
    End Sub
deleting file is as follows.
Code:
Protected Sub FormView1_ItemDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewDeleteEventArgs) Handles FormView1.ItemDeleting
        con.Open()
        Dim musicId As Integer = Convert.ToInt32(Request.QueryString.Get("Id"))
        Dim filePath As String = "select SongPath from Music where Id = " & musicId
        Dim cmd As New SqlCommand(filePath, con)
        cmd.ExecuteNonQuery()
        File.Delete(filePath)
        con.Close()
    End Sub
musicId can be acquired by query string but where I use this query string and how.
Is there any thing wrong with the deleting code. Can you please guide me regarding this, where I should modify the FormView1_ItemDeleting
 
Old November 21st, 2009, 01:10 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hello Sir, well after some fighting with the application I got succeeded to delete the file from physical folder. But If you read my 1st post in this thread I did mention that files are being uploaded but there are 2 files in physical folder for each file uploading. Why it is being happened? And How to get rid off it?
Also some of the files are being uploaded (mp3 music files) properly but some are not (specially any video file viz. .avi, .mpeg, .flv etc.)
How these 2 problems can be solved.
The code snippet that I am using for uploading file is

Code:
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
        Try
            
            Dim theFileUpload As FileUpload = CType( _
                            FormView1.FindControl("FileUpload1"), FileUpload)
            If theFileUpload.HasFile Then
                Dim fileNamePath As String = "~/Music/" & Guid.NewGuid.ToString()
                Dim theExtension As String = Path.GetExtension(theFileUpload.FileName)
                fileNamePath &= theExtension
            
                 theFileUpload.SaveAs(Server.MapPath(fileNamePath))
                e.Values("SongPath") = fileNamePath
                e.Values("SongExtn") = theExtension
            End If
        Catch ex As Exception
            Throw
        End Try
    End Sub
Any help is most respected.
Thank You.....
 
Old November 22nd, 2009, 04:56 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The code itself looks fine so I don't see a reason for this behavior. Maybe you have a Handles for FormView1_ItemInserting in the Code Behind and an "OnItemInserting" in the markup code so the handler is called twice?

Also, don't know why some files would work and others won't. Maybe it's related to their size?

IMar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
sophia (November 23rd, 2009)
 
Old November 23rd, 2009, 01:47 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Thank you sir. I was using "OnItemInserting" in the mark up of code. I removed that function calling, it is working fine now.
But Still struggling with size of file. How we can give permission to accept the large files?
Thank you once again

Last edited by sophia; November 23rd, 2009 at 11:32 AM..
 
Old November 23rd, 2009, 11:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

http://www.google.com/search?hl=en&s...t&aq=f&oq=&aqi=
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
sophia (November 23rd, 2009)
 
Old November 23rd, 2009, 01:16 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Thank you sir, it is working fine. I have added the <httpruntime /> element under system.web and set its attribute "maxRequstLength" to some high value(which is in KB).
and now video files are being uploaded.

Now almost last thing that is left is just to host it.
Hope it will also be done very soon.
Thank you once again.........
 
Old November 25th, 2009, 07:41 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile getting Id of product

Hello Sir, well deleting files from physical folder is working fine. But for that I have to use the Id column to get Id of the product to uniquely identify the product. I don't wanna show this column (I set ShowHeader="false" but it does not work) or don't wanna use hyperlink to get the Id through querystring, but still wanna grab the Id.
The code snippet is as follows.

Code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="5" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" 
        ForeColor ="#333333" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" />
            <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" ShowHeader ="false"  />
            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>
</asp:GridView>
And the code behind file contains the GridView1_RowDeleting to delete the product which is working fine.
But Now how I can get the Id of product?

Thank You.........
 
Old November 25th, 2009, 07:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Sorry, I don't understand what you're asking....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 25th, 2009, 07:57 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

sir I asking that how we can get the Id of any Item without making any field hyperlink field and then fethching the Id through QueryString?
For that I have to use Id bound Field in columns but I don't wanna show this field to the user as it seems some odd
 
Old November 25th, 2009, 08:00 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I know what you're asking, but I don't understand what you're saying. What are you trying to accomplish? What does your code look like? What don't you want to use the query string jada jada jada lalala and so on.....
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
physical address mateenmohd Classic ASP Basics 0 June 13th, 2007 09:24 AM
physical address of application and session ur_sureshin ASP.NET 2.0 Professional 2 May 17th, 2007 03:46 PM
Problem deleting folder in Session_OnEnd Sowee Classic ASP Basics 3 March 9th, 2007 07:18 AM
Hi. Question regarding physical paths in XSL. vlad027 XSLT 0 June 26th, 2003 04:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.