Click here to Skip to main content
15,898,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

my problems is i have using fileupload control & dynamically create this control & upload attachments & sending mail but after email check that time attachments is open only Ist file showing properly data another attachments overright data Ist files to 2nd or multiple files.
Please i have stuck this issue, please give me properly solution.
below the my code.
VB
Dim cnt As Integer = 0
        Dim x As Integer
        For f As Integer = 0 To Request.Files.Count - 1

            Dim Postfile As HttpPostedFile = Request.Files(f)
            Dim filename As HttpPostedFile = Request.Files(x)
            Dim flname As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)

            'Dim attFile As String = flname + flcon
            If Postfile.ContentLength > 0 Then
                If Postfile.ContentLength <= 2048000 Then
                    FileUpload1.PostedFile.SaveAs(Server.MapPath(flname))
                    Dim Atch As New Attachment(Server.MapPath(flname))
              'Dim Atch As New Attachment(FileUpload1.PostedFile.ContentType,flname)
                    at.Add(Atch)
                    cnt += f
                    cnt += x
                    Atch.Dispose()
                End If
            End If
        Next
Posted
Updated 23-Aug-12 22:10pm
v2

1 solution

Hi,

It is because for each file you are fetching file from FileUpload1 control. if you have multiple control then you need to get your file from all corresponding file uploader control. your code logic is incorrect.

Check this[^] link to know about accessing dynamically added control.

Thanks
-Amit Gajjar
 
Share this answer
 
v2
Comments
mangeshrkotkar 24-Aug-12 4:47am    
No, I have using only one fileupload control & create dynamically add fileupload control through button_click(dynamically add - code)that means filename/Id is same, next step i have uploaded attachments variout files & send attachment from mail but i have got mail that time all attachments showing same data(Ist files data/content overwrite) all attachments.
AmitGajjar 24-Aug-12 4:51am    
ok but you are adding this dynamically added file upload control in some panel or table right ? so you need to use FindControl to find control in table cell and then using that control object you can upload file. every time you will get different object. because you need something to distinguish your control. otherwise why dot net framework provide different id for each control. you can also verify your control id from inspecting using FireBug(Addins) in Firefox browser.
AmitGajjar 24-Aug-12 4:52am    
check http://weblogs.asp.net/ksamaschke/archive/2003/04/27/6098.aspx link
mangeshrkotkar 24-Aug-12 6:14am    
no your not getting my problem.
i have getting attachments through mail, suppose i have sending 2 attachment, got the email attachment but 1st attachment showing proper data/content but 2nd attachment showing Ist attachments data it means overwrite.
AmitGajjar 24-Aug-12 6:16am    
I got your point. you have two attachment but both of them have the same content of first attached file. right ? if so then above link will help you to understand how you can resolve it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900