Also, I have a question regarding attached file control
<asp:FileUpload ID="FileUpload" runat="server" Enabled="true" AllowMultiple="true" Width="449px" />
The idea is the following:
I created a contact us page, where a visitor will enter his comments and may or may not attached a file. Once the visitor click on submit.
Two things should happen.
Email will be sent to admin with attachments // this works fine
Attached file is inserted to database table. // posted files disappear ):
The problem I am facing is when I consumed “FileUpload” object when I send email, the code in the method below shows no posted files. however, where I comment out the method that send attachment to email. The postedFiles in the method below contains all the file.
I am not sure if I cannot consume FileUpload.PostedFiles twice. only one time it works, but when I want to consume it twice, by calling email attachment and saving attachment to database it gives me posted files is zero.
please advise and explain thanks
Here is the code that insert the file to database>>>
- protected int pushEmailAttachmentsToDb(string tableName, int intDocOwnerId)
- {
- int rtn = 0;
- try
- {
- string mySql = @" insert into " + tableName + "(docOwnerId ,DocName,ContentType,DocData) " +
- " values(@docOwnerId, @DocName, @ContentType, @DocData)";
-
- foreach (HttpPostedFile postedFile in FileUpload.PostedFiles)
-
- {
- string filename = Path.GetFileName(postedFile.FileName);
- string contentType = postedFile.ContentType;
- using (Stream fs = postedFile.InputStream)
- {
- using (BinaryReader br = new BinaryReader(fs))
- {
- byte[] bytes = br.ReadBytes((Int32)fs.Length);
- CRUD DocInsert = new CRUD();
- Dictionary<string, Object> p = new Dictionary<string, object>();
- p.Add("@docOwnerId", intDocOwnerId);
- p.Add("@DocName", filename);
- p.Add("@ContentType", contentType);
- p.Add("@DocData", bytes);
- rtn = DocInsert.InsertUpdateDelete(mySql, p);
- }
- }
- }
- return rtn;
- }
- catch (Exception ex)
- {
- lblOutput.Text = ex.ToString()
- return rtn;
- }
- }
for more information, click the link below
https://kfmcvlos-my.sharepoint.com/:f:/g/personal/ahameed_kfmc_med_sa/Eg1OuohHZfhBgVsU8qQTNjwBaxBVn67JvU_0BO5o0gtRmw?e=MGPjza
thanks