Comparing two arrays and perform operation [Resolved]

Posted by Rasagna under ASP.NET MVC on 4/18/2016 | Points: 10 | Views : 329 | Status : [Member] | Replies : 4
My problem is I need to display distinct records i.e. files must contain only the records where names obtained from filespath should not match with the slist items.I have tried out the below code.but couldnt achieve it.can anyone suggest changes for this.thanks in advance..

public ActionResult Index()
{
string[] filesPath = Directory.GetFiles(Server.MapPath("~/abc"), "*.pdf");
List<FileInfo> files = new List<FileInfo>();
GetFilesList flist = new GetFilesList();
var list = flist.CategoryList();
string[] slist = list.ToArray();
foreach (string path in filesPath)
{
foreach (var s in slist)
{
string name = Path.GetFileName(path);
if(s != name)
{
files.Add(new FileInfo(Path.GetFileName(path)));
}
}
}
return View(files);
}





Responses

Posted by: Rajnilari2015 on: 4/18/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Use Except ... (Ref: https://msdn.microsoft.com/en-us/library/bb300779(v=vs.100).aspx )

Let us know about the progress

--
Thanks & Regards,
RNA Team

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rasagna on: 4/18/2016 [Member] Starter | Points: 25

Up
0
Down
@Rajnilari thanks for reply but here i am not directly comparing the arrays.I am fetching name from each element using path... and comparing that name with the 2nd array.so I doubt it if i can use except directly.

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 4/18/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
In that case you fill the array and then perform the EXCEPT (:

--
Thanks & Regards,
RNA Team

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rasagna on: 4/18/2016 [Member] Starter | Points: 25

Up
0
Down
@Rajnilari Thanks for reply it worked :)

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response