Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder Cipher's Avatar
    Join Date
    Dec 2004
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Attaching Multiple files

    Can some one give me hint or idea about how can i attach multible files and manage them like the "Manage Attachments" in this forum, my problem is:
    • how to save more than one file with same name.
    • how to attach them to a post if the post is not written yet, so i don't have the PostID yet.

    Last edited by Cipher; 10-08-2005 at 08:10 PM.

  • #2
    Regular Coder Cipher's Avatar
    Join Date
    Dec 2004
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well i got an idea that i can save the file it self in the database, but i dnt know wt datatype shouls i use and also where to save it if i dnt have the post id, i use SqlServer by the way

  • #3
    Regular Coder Cipher's Avatar
    Join Date
    Dec 2004
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well is it that difficult, i need any help, any ideas plz!!

  • #4
    Regular Coder Cipher's Avatar
    Join Date
    Dec 2004
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK!!!!!!!
    i could solve it but i have one problem, is how to delete the attached file and save instead of them other files, please take a look first at the code:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    If Not IsPostBack Then
    Dim Attachments(0) As String
    Session("AttArray") = Attachments
    End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Attachments() As String = Session("AttArray")
    Dim i As Integer = UBound(Attachments)
    If i < 3 Then
    Dim FileName As String = File1.PostedFile.FileName
    FileName = FileName.Substring((FileName.LastIndexOf("\") + 1))
    Dim Extention As String

    'Check fot Extention
    Extention = FileName.Substring((FileName.LastIndexOf(".") + 1)).ToLower
    If Extention <> "jpg" And Extention <> "gif" And Extention <> "zip" Then
    ErrLbl.Visible = True
    ErrLbl.Text = "File type not supported"
    Exit Sub
    End If

    'Check if File Exist
    Dim FileInf As New FileInfo("C:\Inetpub\wwwroot\Forum\Attachments\" & FileName)
    If FileInf.Exists Then
    ErrLbl.Visible = True
    ErrLbl.Text = "File Exist"
    Exit Sub
    End If

    File1.PostedFile.SaveAs(Request.MapPath("Attachments\") & FileName)
    Attachments(i) = FileName
    i += 1
    ReDim Preserve Attachments(i)
    Session("AttArray") = Attachments
    ShowAttachment()
    Else
    ErrLbl.Visible = True
    ErrLbl.Text = "You have reached maxmimum files '3'"
    End If
    End Sub

    Private Sub ShowAttachment()
    Dim Attachments() As String = Session("AttArray")

    Dim HyperLinks(3) As HyperLink
    HyperLinks(0) = HyperLink1
    HyperLinks(1) = HyperLink2
    HyperLinks(2) = HyperLink3

    Dim DelButtons(3) As Button
    DelButtons(0) = AttBtn1
    DelButtons(1) = AttBtn2
    DelButtons(2) = AttBtn3

    Dim i As Integer
    For i = 0 To (UBound(Attachments) - 1)
    HyperLinks(i).Visible = True
    HyperLinks(i).Text = Attachments(i)
    HyperLinks(i).NavigateUrl = Request.MapPath("Attachments\") & Attachments(i)
    DelButtons(i).Visible = True
    DelButtons(i).CommandArgument = i
    Next

    End Sub

    and the picture shows exactly what i want, thanks too much
    Attached Thumbnails Attached Thumbnails Attaching Multiple files-attachments.jpg  
    i need a creative atmosphere

  • #5
    Regular Coder Cipher's Avatar
    Join Date
    Dec 2004
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well i solved alone, here's the code:
    First i made the HyperLinks and DelButtons Global variables.

    Protected Sub DeleteAtt(ByVal sender As System.Object, ByVal e As System.EventArgs)
    HyperLinks(0) = HyperLink1
    HyperLinks(1) = HyperLink2
    HyperLinks(2) = HyperLink3

    DelButtons(0) = AttBtn1
    DelButtons(1) = AttBtn2
    DelButtons(2) = AttBtn3

    Dim btn As Button = CType(sender, Button)
    Dim ArrayNum As Integer = CType(btn.CommandArgument, Integer)
    Dim Attachments() As String = Session("AttArray")
    Dim FileName As String = Attachments(ArrayNum)

    Attachments.Clear(Attachments, ArrayNum, 1)
    ReDim Preserve Attachments(UBound(Attachments) - 1)
    Session("AttArray") = Attachments
    System.IO.File.Delete(Request.MapPath("Attachments\") & FileName)

    HyperLinks(ArrayNum).Visible = False
    DelButtons(ArrayNum).Visible = False

    ShowAttachment()
    End Sub
    i need a creative atmosphere

  • #6
    Regular Coder Cipher's Avatar
    Join Date
    Dec 2004
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well i feel i'm talking 2 my self, but there's still a problem, when i delete from top to down it dont work well, i guess the problem is that when i delete the first elemnt in array i cant put smthing in its place.
    i need a creative atmosphere


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •