TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Al
NA
30
6.2k
FileUpload control - files disappears
Apr 16 2020 12:00 PM
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)"
;
// 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
Reply
Answers (
3
)
I am trying to POST data to API
How to change color of column in column chart using asp.net?