本文介绍了我该如何解决这个错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够查看我的图像,但我继续得到这个
错误:mscorlib中出现'System.IO.DirectoryNotFoundException'类型的异常。 dll但未在用户代码中处理
附加信息:找不到路径'C:\ Users \Mella \Documents \ Myy的一部分LiveAdvert项目(7月至8月)\ LiveAds\LiveAdverts\LiveAdverts\Images \'。
这是我的代码:
public class ImageHandler:IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
{
System.Data.SqlClient.SqlDataReader rdr = null ;
System.Data.SqlClient.SqlConnection conn = null ;
System.Data.SqlClient.SqlCommand selcmd = null ;
尝试
{
// string path =
conn = new System.Data.SqlClient.SqlConnection
(System.Configuration。 ConfigurationManager.ConnectionStrings [ LiveAdsConnectionString]。ConnectionString);
selcmd = new System.Data.SqlClient.SqlCommand( 从广告中选择图像,其中AdvertsID = +
context.Request.QueryString [ id],conn);
conn.Open();
rdr = selcmd.ExecuteReader();
while (rdr.Read())
{
context.Response.ContentType = image / jpg;
context.Response.ContentType = image / png;
context.Response.WriteFile( / Images / + rdr [ Image]。ToString());
}
if (rdr!= null )
rdr.Close();
}
最后
{
如果(conn != null )
conn.Close();
}
}
}
public bool IsReusable
{
get
{
return false ;
}
}
}
解决方案
I am able to view my images but i keep on getting this
error: "An exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll but was not handled in user code
Additional information: Could not find a part of the path 'C:\Users\Mella\Documents\My LiveAdvert Project(July-August)\LiveAds\LiveAdverts\LiveAdverts\Images\'."
Here's my code:
public class ImageHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { { System.Data.SqlClient.SqlDataReader rdr = null; System.Data.SqlClient.SqlConnection conn = null; System.Data.SqlClient.SqlCommand selcmd = null; try { //string path ="" conn = new System.Data.SqlClient.SqlConnection (System.Configuration.ConfigurationManager.ConnectionStrings["LiveAdsConnectionString"].ConnectionString); selcmd = new System.Data.SqlClient.SqlCommand("select Image from Adverts where AdvertsID=" + context.Request.QueryString["id"], conn); conn.Open(); rdr = selcmd.ExecuteReader(); while (rdr.Read()) { context.Response.ContentType = "image/jpg"; context.Response.ContentType = "image/png"; context.Response.WriteFile("/Images/" + rdr["Image"].ToString()); } if (rdr != null) rdr.Close(); } finally { if (conn != null) conn.Close(); } } } public bool IsReusable { get { return false; } } }
解决方案
这篇关于我该如何解决这个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!