简体   繁体   中英

Access to the path is denied asp.net

I tried to use this code to retrieve image from sql database and show it in Image1 asp control:

cn.Open();
    SqlCommand cm = new SqlCommand("select * from ImageCollection where img_id='" + DropDownList1.SelectedItem.ToString() + "'", cn);
    SqlDataAdapter da = new SqlDataAdapter(cm);
    SqlDataReader dr = cm.ExecuteReader();
    try
    {
        if (dr.Read())
        {

            string image1 = Convert.ToString(DateTime.Now.ToFileTime());
            FileStream fs1 = new FileStream(image1, FileMode.CreateNew, FileAccess.Write);
            byte[] bimage1 = (byte[])dr["passport_photo"];
            fs1.Write(bimage1, 0, bimage1.Length - 1);
            fs1.Flush();
            Image1.ImageUrl = "~/images/"+DropDownList1.SelectedItem.ToString();
        }
        dr.Close();
        cn.Close();
    }
    catch (Exception ex)
    {
        throw ex;
    }

But I ended up with this:

Access to the path 'C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\DevServer\\10.0\\130301775684384514' is denied.

How can I overcome that without changing the whole code (the way).

string base64String = Convert.ToBase64String(bytes, 0, bytes.Length); 
Image1.ImageUrl = "data:image/png;base64," + base64String;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM