C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » XML »

Searching a XML file form Folders Using Generics


Posted Date: 10 Sep 2008    Resource Type: Articles    Category: XML
Author: Makesh Member Level: Silver    
Rating: 1 out of 5Points: 10



This code demonstrate how to search for a xml file in folder using Generics from dot net 2.0


using System.Collections.Generic;
private string GetSearchPacketReqId(string pathofbasefolder, string filename)
{
try
{
string strFileName = "";
string strReqId = filename + ".xml";
Stack directoryStack = new Stack();
directoryStack.Push(baseDir);

while (directoryStack.Count > 0)
{
string currentDir = directoryStack.Pop();

foreach (string fileNamePath in Directory.GetFiles(currentDir, "*.*"))
{

StringBuilder strBuilder = new StringBuilder();
strBuilder.Append(fileNamePath);
strBuilder.Remove(0, currentDir.Length + 1);
if (strReqId == strBuilder.ToString())
{
//XML file name that you search
strFileName = fileNamePath;
return strFileName;
}
}

foreach (string directoryName in Directory.GetDirectories(currentDir))
{
directoryStack.Push(directoryName);
}
}
return strFileName;
}
catch (Exception ex)
{
throw ex;
}
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Search  .  Generics  .  Folders  .  Files  .  Dot net 2.0  .  "Searching a XML file from folders"  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Previous Resource: XML DOM Object Model
Return to Discussion Resource Index
Post New Resource
Category: XML


Post resources and earn money!
 



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use