...

View Full Version : Attaching Multiple files



Cipher
10-08-2005, 07:02 PM
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.

:o

Cipher
10-09-2005, 01:54 PM
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

Cipher
10-11-2005, 11:44 AM
well is it that difficult, i need any help, any ideas plz!! :o

Cipher
10-13-2005, 05:28 PM
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

Cipher
10-13-2005, 08:11 PM
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

Cipher
10-13-2005, 11:52 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum