如何descard图像网址 [英] how to descard image url

查看:196
本文介绍了如何descard图像网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我有2个按钮,其中一个上传图像,另一个删除它。

在我的代码中有一个< asp:image>还有哪一个上传图片asp:图片显示图片和删除图片后应该从表单中消失。



我的添加按钮具有以下代码:



Hi all .

i have 2 buttons one of them upload an image and another delete it .
In my code there is an <asp:image> also which as soon as upload image asp:image show that image and after deleting image should disappear from the form .

my add button has the below code :

protected void Btn_upload_Click(object sender, EventArgs e)
{

    //To upluad image into tbl_Img and get its id .
    try
    {
        con.Open();
        SqlCommand cmdInsert = new SqlCommand("insert into tbl_Img (Fld_Uploader,Fld_path,Fld_FileName) values ('Admin','" + PublicClass.ImgPath() + "','" + File_Upload.FileName + "')", con);
        cmdInsert.ExecuteNonQuery();

        SqlCommand cmdGetId = new SqlCommand("select top 1 * from tbl_img order by fld_id desc", con);
        SqlDataAdapter da = new SqlDataAdapter(cmdGetId);
        DataTable dt = new DataTable();
        da.Fill(dt);

        ImgID = dt.Rows[0]["Fld_id"].ToString();
        RandCode = dt.Rows[0]["Fld_RandCode"].ToString();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }

    try
    {
        ImgPath = Server.MapPath(PublicClass.ImgPath() + ImgID + "_" + File_Upload.FileName);
        File_Upload.SaveAs(ImgPath);
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }

    Img.ImageUrl = "../../ReadAttachment.aspx?code=" + RandCode + "&maxWidth=100&maxHeight=100"; //the problem is from here . if i comment this line there will be no error . 

    BtnDelete.Visible = true;
    btnAdd.Enabled = true;
} 





和我的删除btn有这段代码:





and my Delete btn has this code :

protected void BtnDelete_Click(object sender, EventArgs e)
{
    try
    {
        if (System.IO.File.Exists(ImgPath))
        {
            Img.ImageUrl = "";
            System.IO.File.Delete(ImgPath); //ImgPath is a global varoable
            Response.Write("Deleted");
        }
        else
        {
            Response.Write("its not exist");
        }
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
}





但是在删除按钮时出现此错误:



该进程无法访问文件'L:\ chikardarin Website \ WebApplication2 \ image_logo \ _11_nissan-cars-logo-emblem.jpg'因为它正被使用通过另一个过程。





注意:此示例在localHost上运行。

请告诉我如何在删除时丢弃我的image-url。谢谢:)



but at delete button i get this error :

The process cannot access the file 'L:\chikardarin Website\WebApplication2\image_logo\11_nissan-cars-logo-emblem.jpg' because it is being used by another process.


note : this example is run on localHost .
please tell me how to discard my image-url at delete time . thank you :)

推荐答案

检查在Web服务器上上传图像的文件夹的权限。


这篇关于如何descard图像网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆