Click here to Skip to main content
15,123,118 members
Home / Discussions / C#
   

C#

 
GeneralRe: Certificate in TCPListnear Pin
Jaimesh.241122-May-16 22:11
MemberJaimesh.241122-May-16 22:11 
AnswerRe: Certificate in TCPListnear Pin
Afzaal Ahmad Zeeshan22-May-16 22:18
mveAfzaal Ahmad Zeeshan22-May-16 22:18 
GeneralRe: Certificate in TCPListnear Pin
Jaimesh.241122-May-16 22:21
MemberJaimesh.241122-May-16 22:21 
GeneralRe: Certificate in TCPListnear Pin
Afzaal Ahmad Zeeshan22-May-16 22:35
mveAfzaal Ahmad Zeeshan22-May-16 22:35 
QuestionHow to read XML with directory structure Pin
Member 244330620-May-16 12:28
MemberMember 244330620-May-16 12:28 
AnswerRe: How to read XML with directory structure Pin
Karthik_Mahalingam21-May-16 23:46
professionalKarthik_Mahalingam21-May-16 23:46 
GeneralRe: How to read XML with directory structure Pin
Member 244330622-May-16 10:12
MemberMember 244330622-May-16 10:12 
GeneralRe: How to read XML with directory structure Pin
Member 244330622-May-16 13:53
MemberMember 244330622-May-16 13:53 
I played around and did a realy dirty and probably inefficent solution OMG | :OMG: for the problem (SHA256 was additionally added to XML):

C#
using (var reader = new XmlTextReader(@"c:\Users\andre\Documents\Test3.xml"))
            {
                List<string> myDir = new List<string>(); //For creating Directory structure
                //For start Tags:
                bool isFile = false;   
                bool isFileName = false;
                bool isSHA = false;
                bool isLength = false;
                //File Data
                string curFile = "";
                string curLength = "";
                string curSHA = "";

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.XmlDeclaration: //Start of XML
                             break;
                        case XmlNodeType.Element: // The node is an element, if DIR get attribute, else set flags
                            if (reader.Name.ToString().Equals("Dir",StringComparison.OrdinalIgnoreCase))
                            {
                                //Its a new directory, add it to List
                                myDir.Add(reader.GetAttribute("Name"));
                                isFile = false;
                            }//dir
                            else if (reader.Name.ToString().Equals("File", StringComparison.OrdinalIgnoreCase))
                                {
                                    //A File-Info will follow
                                    isFile = true;
                                    //curFile = reader.Value;
                                }//File
                            else if (reader.Name.ToString().Equals("Name", StringComparison.OrdinalIgnoreCase))
                            {
                                //A Filename will follow
                                if (isFile)
                                {
                                    isFileName = true;
                                }
                                else
                                {
                                    //just to catch error
                                    Console.WriteLine("error on Line {0} Name <{1}> Value{2}",reader.LineNumber,reader.Name,reader.Value);
                                }
                            }//Name
                            else if (reader.Name.ToString().Equals("Length", StringComparison.OrdinalIgnoreCase))
                            {
                                //A file lenght will follow
                                if (isFile)
                                {
                                    isLength = true;
                                }
                                else
                                {
                                    //just to catch error
                                    Console.WriteLine("error on Line {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
                                }
                                
                            }//Length
                            else if (reader.Name.ToString().Equals("SHA256", StringComparison.OrdinalIgnoreCase))
                            {
                                if (isFile)
                                {
                                    isSHA = true;
                                }
                                else
                                {
                                    //just to catch error
                                    Console.WriteLine("error on Line {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
                                }
                                
                            }//SHA256
                            else
                            {
                                //just to catch error
                                Console.WriteLine("Unknown Element {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
                                
                            }//all others
                            break;
                        case XmlNodeType.Text: //Display the text in each element.
                            //Check if the following text is any data for the file
                            if (isFileName)
                            {
                                curFile = reader.Value;
                            }
                            else if (isSHA){
                                curSHA = reader.Value;
                            }
                            else if (isLength)
                            {
                                curLength = reader.Value;
                            }
                            else
                            {
                                //just to catch error
                                Console.WriteLine("Unknown Text Line {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
                            }
                            break;
                        case XmlNodeType.EndElement: //Display the end of the element.
                            if (reader.Name.ToString().Equals("dir", StringComparison.OrdinalIgnoreCase))
                            {
                                myDir.Remove(myDir.Last());
                                isFile = false;
                            }
                            else if (reader.Name.ToString().Equals("File", StringComparison.OrdinalIgnoreCase))
                            {
                                //File element was closed, we must have all data for that file
                                isFile = false;
                                Console.WriteLine("Path: {0}",string.Join("\\", myDir.ToArray()));
                                if (!curSHA.Equals("")) {
                                    Console.WriteLine(" File: {0} Length: {1} SHA256: {2}",curFile,curLength,curSHA);
                                }
                                else
                                {
                                    Console.WriteLine(" File: {0} Length: {1}", curFile, curLength);
                                }
                                

                            }
                            //Set flags to false for closing elements
                            else if (reader.Name.ToString().Equals("Length", StringComparison.OrdinalIgnoreCase))
                            {
                                isLength = false;
                            }
                            else if (reader.Name.ToString().Equals("SHA256", StringComparison.OrdinalIgnoreCase))
                            {
                                isSHA = false;
                            }
                            else if (reader.Name.ToString().Equals("Name", StringComparison.OrdinalIgnoreCase))
                            {
                                isFileName = false;
                            }
                            else {
                                //just to catch error
                                Console.WriteLine("Unknown End element {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
                            }
                            break;
                    }//End Switch
                }//end While
                //await Task.Run(() => CreateXML(progress));
            }//end Using

(Note: string.Join()-Line destroys coloring)

Even it is not nice as it's not mucht better than just textparsing and manual decoding the XML Dead | X| , it works:

Path: Tmp\ConsoleApplication1\bin\Debug
 File: ConsoleApplication1.exe Length: 4608
Path: Tmp\ConsoleApplication1\bin\Debug
 File: ConsoleApplication1.pdb Length: 11776
Path: Tmp\ConsoleApplication1\bin\Debug
 File: ConsoleApplication1.vshost.exe Length: 9568
Path: Tmp\ConsoleApplication1\bin\Debug
 File: ConsoleApplication1.vshost.exe.manifest Length: 473
Path: Tmp\ConsoleApplication1\obj\Debug\TempPE
 File: ConsoleApplication1.csproj.FileListAbsolute.txt Length: 322
Path: Tmp\ConsoleApplication1\obj\Debug\TempPE
 File: ConsoleApplication1.exe Length: 4608
Path: Tmp\ConsoleApplication1\obj\Debug\TempPE
 File: ConsoleApplication1.pdb Length: 11776
Path: Tmp\ConsoleApplication1\obj\Properties
 File: AssemblyInfo.cs Length: 1454
Path: Tmp\ConsoleApplication1\obj
 File: ConsoleApplication1.csproj Length: 2546
Path: Tmp\ConsoleApplication1\obj
 File: ConsoleApplication1.sln Length: 937
Path: Tmp\ConsoleApplication1\obj
 File: ConsoleApplication1.suo Length: 10752
Path: Tmp\ConsoleApplication1\obj
 File: Program.cs Length: 269


If anyone has a better Blush | :O solution: youre welcome!!!

I'm still serious if theres not a easyser solution to revert back this (my current test) 1-Liner:
C#
return new XElement("Dir",
                    new XAttribute("Name", di.Name),
                    from d in Directory.GetDirectories(source)
                    select CreateFileSystemXmlTree(d, progress), //add progressbar
                    from fi in di.GetFiles()
                       let myProgress = DoProgress(progress) //progressbar
                    select new XElement("File",
                        //new XElement("Name", fi.FullName),
                        new XElement("Name", fi.Name),
                        new XElement("Length", fi.Length),
                        new XElement("SHA256", GetChecksumBuffered(fi.FullName))
                    )
                );

SuggestionRe: How to read XML with directory structure Pin
Richard Deeming23-May-16 2:44
mveRichard Deeming23-May-16 2:44 
GeneralRe: How to read XML with directory structure Pin
Member 244330623-May-16 14:46
MemberMember 244330623-May-16 14:46 
QuestionIs there a source code download for this article? Pin
Member 1253641620-May-16 11:59
MemberMember 1253641620-May-16 11:59 
AnswerRe: Is there a source code download for this article? Pin
Pete O'Hanlon20-May-16 12:21
mvePete O'Hanlon20-May-16 12:21 
GeneralRe: Is there a source code download for this article? Pin
Richard Deeming20-May-16 12:28
mveRichard Deeming20-May-16 12:28 
GeneralRe: Is there a source code download for this article? Pin
Member 1253641620-May-16 12:32
MemberMember 1253641620-May-16 12:32 
AnswerRe: Is there a source code download for this article? Pin
Richard Deeming20-May-16 12:33
mveRichard Deeming20-May-16 12:33 
JokeRe: Is there a source code download for this article? Pin
Member 1253641620-May-16 21:01
MemberMember 1253641620-May-16 21:01 
Questiondelete directory / folder recursive, by pass locked files Pin
jkirkerx20-May-16 11:53
professionaljkirkerx20-May-16 11:53 
AnswerRe: delete directory / folder recursive, by pass locked files Pin
Member 244330620-May-16 12:50
MemberMember 244330620-May-16 12:50 
GeneralRe: delete directory / folder recursive, by pass locked files Pin
jkirkerx20-May-16 13:30
professionaljkirkerx20-May-16 13:30 
AnswerProblem 2, access the HKLM as Admin doesn't work Pin
jkirkerx20-May-16 13:36
professionaljkirkerx20-May-16 13:36 
GeneralRe: Problem 2, access the HKLM as Admin doesn't work Pin
Member 244330620-May-16 13:53
MemberMember 244330620-May-16 13:53 
GeneralRe: Problem 2, access the HKLM as Admin doesn't work Pin
jkirkerx21-May-16 13:00
professionaljkirkerx21-May-16 13:00 
GeneralRe: Problem 2, access the HKLM as Admin doesn't work Pin
jkirkerx22-May-16 8:28
professionaljkirkerx22-May-16 8:28 
AnswerRe: delete directory / folder recursive, by pass locked files [done] Pin
jkirkerx22-May-16 8:31
professionaljkirkerx22-May-16 8:31 
GeneralRe: delete directory / folder recursive, by pass locked files [done] Pin
Member 244330622-May-16 10:14
MemberMember 244330622-May-16 10:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.