Searching and Retriving image from a folder

neel

hi i am doing a project in MVC4 using c#. in my project i am storing some group of persons details in database with unique id.and also storing the profile pic of particular person in a folder in my project.(Id number and pic name is same). in view i want display all these details.Problem is in images. I use the following codes

View

   @foreach(var item in Model)
    {
       <td><img src="@Url.Action("ImageRetrive", "Member", new {imgname=(item.Id)})" /><br />Rtn. @item.Mem_NA<br />(@item.Mem_Occ)</td>
    }

controller

    public string ImageRetrive(int imgname)
    {
        string keyword=image.ToString();
        string imagefolderpath = Server.MapPath("~/Content/Member/MemberPhotos");
        string currentimage  = new Member().GetImage(imagefolderpath,keyword);
        string fullpath = "~/Content/Member/MemberPhotos/" + currentimage;
        return fullpath;

    }

model

   public string GetImage(string path,string keyword)
    {
       DirectoryInfo di = new DirectoryInfo(path);
        FileInfo[] images = di.GetFiles();
        foreach (FileInfo image in images)
        {
            var name = image.Name;
            if (name.Contains(keyword))
            {
                imgname = name;
            }
        }
        return imgname;
    }

But i didnot get any output. in the controller the variable fullpath is giving the link. but it can take in . Please help me.

Satpal

I think you need is FilePathResult, change your controller code as

public FilePathResult  ImageRetrive(int imgname)
{
    string keyword=image.ToString();
    string imagefolderpath = Server.MapPath("~/Content/Member/MemberPhotos");
    string currentimage  = new Member().GetImage(imagefolderpath,keyword);
    string fullpath = "~/Content/Member/MemberPhotos/" + currentimage;

    return File(fullpath, "image/png"); //Changed here
}

or You can use FileContentResult

public FileContentResult Retrive(int imgname)
{
    return File(ConvertToByteArray(YourFile), "image/png"); //Changed here
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Uploading and retriving image from mysql database

From Dev

retriving image from from database through mysqli using php is not working

From Dev

Searching for objects from database on image

From Dev

Excluding folder from PHPstorm indexing and error searching

From Dev

cakephp retriving values from combobox

From Dev

Delete image from folder

From Dev

Displaying image from a folder

From Java

Retriving certain amount of rows from dataframe

From Dev

Retriving a value from Array of Vector Value

From Dev

Rails. Retriving country user is accessing from

From Dev

Javascript wait asynch retriving data from Firebase

From Dev

Data from the SQLIte is not retriving in recycler view

From Dev

Retriving a value from Array of Vector Value

From Dev

Retriving selected value from cell in HTML table

From Dev

Rails. Retriving country user is accessing from

From Dev

Retriving data from tags with a certain value

From Dev

Retriving Data From Firebase In DataSnapshot ( Not In Sequence )

From Dev

Numpy: Retriving an array from an array of pointers

From Dev

Using func while retriving date from database

From Dev

Create ISO image from folder

From Dev

Converting image from project folder

From Dev

WPF load image from folder

From Dev

My Image is not removing from folder

From Dev

not able to display image from a folder

From Dev

Not searching for view in Areas folder

From Dev

Retriving all records from left table and matching records from right

From Dev

Retriving the count from one table given a value from another

From Dev

Retriving values from generated text box using jquery

From Dev

Retriving the value from textfields having same class in javascript

Related Related

HotTag

Archive