Sandeep Kumar

Sandeep Kumar

  • 1.1k
  • 683
  • 60.3k

how to show image in window open from path in java script using web

Nov 10 2021 3:31 AM

i want to show the image in window.open from image path where it is stored in java scripts.

function DownloadFile(id) {
    $.ajax({
       type: "POST",
       url: '<%=ResolveUrl("~/Account/UserManagement.aspx/DownloadFiles")%>',
        data: "{'id':'" + id + "'}",
       contentType: "application/json; charset=utf-8",
       datatype: "json",
       success: function (data) {
           var msg = eval('(' + data.d + ')');
           var url = msg[0].FilePath;
           img = '<img src="' + url + '">';
           popup = window.open(img);

.CS Code

[WebMethod]
public static string DownloadFiles(string id)
{
    string data = string.Empty;
    try
    {
        DataTable dt = MasterEntry.GetFileName(id);

        var obj = from row in dt.AsEnumerable()
                  select new
                  {
                      FilePath = row["FilePath"].ToString(),
                  };
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        data = serializer.Serialize(obj);
        return data;
    }
    catch
    {
        return data;
    }
}

plesae help me as soon as possible


Answers (3)