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
Paul Rajs
NA
641
146.9k
Unable to cast object of type 'System.String' to type 'Syste
Feb 3 2016 1:38 AM
Hi, Developers ,
My code for load a attached file from database.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbConnection con = Connection.DBconnection();
OleDbCommand com = new OleDbCommand("select Name,type,data from WordFiles where id=@id", con);
com.Parameters.AddWithValue("id", GridView1.SelectedRow.Cells[1].Text);
OleDbDataReader dr = com.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = dr["type"].ToString();
Response.AddHeader("content-disposition", "attachment;filename=" + dr["Name"].ToString()); // to open file prompt Box open or Save file
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite((byte[])dr["data"]);
Response.End();
}
}
if i click the download link na it will be downloaded.but
When i am try to download a attachment file it throws the following error.
Unable to cast object of type 'System.String' to type 'System.Byte[]'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Byte[]'.
Source Error:
Line 100: Response.Charset = "";
Line 101: Response.Cache.SetCacheability(HttpCacheability.NoCache);
Line 102: Response.BinaryWrite((byte[])dr["data"]);
Line 103: Response.End();
Line 104: }
So please help me to how i am resolve this error.
Thanks with
Paul.S
Reply
Answers (
2
)
How to Login WebApi TO MVC5 Proejct
Using nuget datepicker