Also, I have a question regarding attached file control
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)";
- // save files to DB
- foreach (HttpPostedFile postedFile in FileUpload.PostedFiles) // here is the issue, postedFiles is empty.
- // foreach (HttpPostedFile postedFile in myUploadedFiles.)
- {
- 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(); // added Nov 2017
- Dictionary<string, Object> p = new Dictionary<string, object>();
- p.Add("@docOwnerId", intDocOwnerId); // mySenderId
- 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
Jignesh KumarPosted Apr 26, 2020, 12:24 AM
AlPosted Apr 25, 2020, 7:36 PM
Salman BegPosted Apr 16, 2020, 12:56 PM