Click here to Skip to main content
15,885,767 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionRe: Access from data from Ms access Pin
Praveen Kandari26-Feb-15 1:16
Praveen Kandari26-Feb-15 1:16 
AnswerRe: Access from data from Ms access Pin
Richard MacCutchan26-Feb-15 2:00
mveRichard MacCutchan26-Feb-15 2:00 
GeneralRe: Access from data from Ms access Pin
Praveen Kandari26-Feb-15 17:04
Praveen Kandari26-Feb-15 17:04 
Questionaccess data from ms access with date Pin
Praveen Kandari26-Feb-15 1:13
Praveen Kandari26-Feb-15 1:13 
SuggestionRe: access data from ms access with date Pin
ZurdoDev26-Feb-15 4:16
professionalZurdoDev26-Feb-15 4:16 
GeneralRe: access data from ms access with date Pin
Praveen Kandari26-Feb-15 17:06
Praveen Kandari26-Feb-15 17:06 
QuestionRe: access data from ms access with date Pin
ZurdoDev27-Feb-15 1:31
professionalZurdoDev27-Feb-15 1:31 
QuestionDelete files from server folders Pin
Sean_Vt25-Feb-15 8:36
Sean_Vt25-Feb-15 8:36 
I've googled but cannot find a solution that works. I've found and gotten to work uploading, viewing and downloading files to/from folders on my server. These are shown in bound gridviews on 2 pages. Now what i need is to allow the user to delete files when they are out of date. Below is the code. If anyone can point me in the right directions i would greatly appreciate it!

XML
Attachments:<asp:FileUpload ID="fileUpload1" runat="server" /><br />
<asp:Button ID="btnUpload" runat="server" Text="Upload" onclick="btnUpload_Click" usesubmitbehavior="false"/>

XML
<asp:GridView ID="gvDetails" CssClass="Gridview" runat="server"
        AutoGenerateColumns="False"
        DataSourceID="SqlDataSource2">
<HeaderStyle BackColor="#df5015" />
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" Visible="False" />
    <asp:BoundField DataField="filepath" HeaderText="filepath" Visible="False" />
<asp:BoundField DataField="FileName" HeaderText="File Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
    <asp:BoundField DataField="CVSNumber" HeaderText="Company Auto" Visible="False" />

</Columns>
</asp:GridView>


VB Code-
VB
' Save files to Folder and files path in database
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) 'Handles btnUpload.Click
    Dim cvsfilename As String = Path.GetFileName(fileUpload1.PostedFile.FileName)

    Dim firmcvs As String = CompanyAuto_TB.Text

    fileUpload1.SaveAs(Server.MapPath("files/" & cvsfilename))

    sql = "Insert INTO tblFiles(Filename, Filepath,CVSNumber) "
    sql += "values(@Name,@PAth,@CompanyAuto_tb) "

    Dim cmd As SqlCommand = New SqlCommand(sql, New SqlConnection(conString))
    cmd.Parameters.AddWithValue("@Name", cvsfilename)
    cmd.Parameters.AddWithValue("@Path", "files/" & cvsfilename)
    cmd.Parameters.AddWithValue("@CompanyAuto_tb", firmcvs)

    Try
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
    Catch ex As Exception
        Response.Write(ex.ToString())
    Finally
        If cmd IsNot Nothing Then
            If cmd.Connection.State <> ConnectionState.Closed Then
                cmd.Connection.Close()
            End If
            cmd.Dispose()
        End If

    End Try





' This button click event is used to download files from gridview
Protected Sub lnkDownload_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim lnkbtn As LinkButton = TryCast(sender, LinkButton)
    Dim gvrow As GridViewRow = TryCast(lnkbtn.NamingContainer, GridViewRow)
    Dim filePath As String = gvDetails.DataKeys(gvrow.RowIndex).Value.ToString()
    Response.ContentType = "image/jpg"
    Response.AddHeader("Content-Disposition", "attachment;filename=""" & filePath & """")
    Response.TransmitFile(Server.MapPath(filePath))
    Response.[End]()
End Sub

AnswerRe: Delete files from server folders Pin
Afzaal Ahmad Zeeshan25-Feb-15 21:45
professionalAfzaal Ahmad Zeeshan25-Feb-15 21:45 
GeneralRe: Delete files from server folders Pin
Sean_Vt25-Feb-15 23:21
Sean_Vt25-Feb-15 23:21 
AnswerRe: Delete files from server folders Pin
Afzaal Ahmad Zeeshan25-Feb-15 23:41
professionalAfzaal Ahmad Zeeshan25-Feb-15 23:41 
GeneralRe: Delete files from server folders Pin
Sean_Vt25-Feb-15 23:58
Sean_Vt25-Feb-15 23:58 
AnswerRe: Delete files from server folders Pin
Afzaal Ahmad Zeeshan26-Feb-15 0:02
professionalAfzaal Ahmad Zeeshan26-Feb-15 0:02 
GeneralRe: Delete files from server folders Pin
Sean_Vt26-Feb-15 0:05
Sean_Vt26-Feb-15 0:05 
AnswerRe: Delete files from server folders Pin
Afzaal Ahmad Zeeshan26-Feb-15 0:14
professionalAfzaal Ahmad Zeeshan26-Feb-15 0:14 
GeneralRe: Delete files from server folders Pin
Sean_Vt26-Feb-15 6:09
Sean_Vt26-Feb-15 6:09 
QuestionAccess from data from Ms access Pin
Praveen Kandari24-Feb-15 20:31
Praveen Kandari24-Feb-15 20:31 
QuestionRe: Access from data from Ms access Pin
Richard MacCutchan25-Feb-15 4:28
mveRichard MacCutchan25-Feb-15 4:28 
AnswerRe: Access from data from Ms access Pin
Praveen Kandari25-Feb-15 17:52
Praveen Kandari25-Feb-15 17:52 
GeneralRe: Access from data from Ms access Pin
Richard MacCutchan25-Feb-15 21:32
mveRichard MacCutchan25-Feb-15 21:32 
GeneralRe: Access from data from Ms access Pin
Praveen Kandari25-Feb-15 22:41
Praveen Kandari25-Feb-15 22:41 
GeneralRe: Access from data from Ms access Pin
Richard MacCutchan25-Feb-15 22:48
mveRichard MacCutchan25-Feb-15 22:48 
QuestionASP.Net button appears twice in run time Pin
sudevsu24-Feb-15 8:52
sudevsu24-Feb-15 8:52 
QuestionRe: ASP.Net button appears twice in run time Pin
jkirkerx24-Feb-15 10:31
professionaljkirkerx24-Feb-15 10:31 
AnswerRe: ASP.Net button appears twice in run time Pin
sudevsu27-Feb-15 3:23
sudevsu27-Feb-15 3:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.