Click here to Skip to main content
15,891,777 members
Home / Discussions / C#
   

C#

 
GeneralRe: Same EXE vs Different EXE Pin
Mycroft Holmes6-Aug-14 23:10
professionalMycroft Holmes6-Aug-14 23:10 
GeneralRe: Same EXE vs Different EXE Pin
KUMAR6196-Aug-14 23:49
professionalKUMAR6196-Aug-14 23:49 
GeneralRe: Same EXE vs Different EXE PinPopular
Mycroft Holmes7-Aug-14 0:57
professionalMycroft Holmes7-Aug-14 0:57 
GeneralRe: Same EXE vs Different EXE PinPopular
GuyThiebaut7-Aug-14 2:44
professionalGuyThiebaut7-Aug-14 2:44 
GeneralRe: Same EXE vs Different EXE Pin
Bernhard Hiller7-Aug-14 21:11
Bernhard Hiller7-Aug-14 21:11 
AnswerRe: Same EXE vs Different EXE Pin
Akhil Mittal7-Aug-14 20:05
professionalAkhil Mittal7-Aug-14 20:05 
QuestionCall a SAP transaction, execute with given parameters and download a report with C# Pin
Goliadkin6-Aug-14 16:41
Goliadkin6-Aug-14 16:41 
AnswerRe: Call a SAP transaction, execute with given parameters and download a report with C# Pin
Goliadkin7-Aug-14 15:07
Goliadkin7-Aug-14 15:07 
QuestionXML usage Pin
eblaschka6-Aug-14 14:26
eblaschka6-Aug-14 14:26 
AnswerRe: XML usage Pin
Dave Kreskowiak6-Aug-14 17:08
mveDave Kreskowiak6-Aug-14 17:08 
AnswerRe: XML usage Pin
Bernhard Hiller6-Aug-14 20:49
Bernhard Hiller6-Aug-14 20:49 
AnswerRe: XML usage Pin
Richard Deeming7-Aug-14 1:35
mveRichard Deeming7-Aug-14 1:35 
GeneralRe: XML usage Pin
eblaschka10-Aug-14 11:39
eblaschka10-Aug-14 11:39 
GeneralRe: XML usage Pin
Richard Deeming11-Aug-14 1:53
mveRichard Deeming11-Aug-14 1:53 
The problem with your second method is that your <Value>, <Key> and <RootKey> elements don't contain an element called "Contents". That means that you'll get the value from the <Contents> element under the <Data> element, and an empty string for each ancestor element.

If you just want to append the value from the <Contents> element to the path, then use:
C#
static string GetFullPathToKey(XElement dataElement)
{
    var names = new HashSet<XName> { "RootKey", "Key", "Value", "Data" };

    IEnumerable<string> pathParts = dataElement.AncestorsAndSelf()
        .Where(el => names.Contains(el.Name))
        .Select(el => (string)el.Element("Name") ?? (string)el.Element("Contents"))
        .Reverse();

    return string.Join("\\", pathParts);
}

IList<string> Regs = document.Descendants("Data").Select(GetFullPathToKey).ToList();
/*
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Features\8CD5D2FB0DBCDD64A8D2AB1D09CAF271\ClientPrograms\ 
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Features\8CD5D2FB0DBCDD64A8D2AB1D09CAF271\DataFiles\Server 
*/


If you want to include the <Action>, <Type> and <Content> in a different format, then try something like this:
C#
static string GetFullPathToKey(XElement dataElement)
{
    var names = new HashSet<XName> { "RootKey", "Key", "Value" };

    IEnumerable<string> pathParts = dataElement.AncestorsAndSelf()
        .Where(el => names.Contains(el.Name))
        .Select(el => (string)el.Element("Name"))
        .Reverse();

    string fullPath = string.Join("\\", pathParts);

    string details = string.Format(" {{ Action: '{0}', Type: '{1}', Contents: '{2}' }}",
        (string)dataElement.Element("Action"),
        (string)dataElement.Elements("After").Elements("Data").Elements("Type").FirstOrDefault(),
        (string)dataElement.Elements("After").Elements("Data").Elements("Contents").FirstOrDefault());

    return fullPath + details;
}

IList<string> Regs = document.Descendants("Value").Select(GetFullPathToKey).ToList();
/*
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Features\8CD5D2FB0DBCDD64A8D2AB1D09CAF271\ClientPrograms { Action: 'Created', Type: 'REG_SZ', Contents: '' } 
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Features\8CD5D2FB0DBCDD64A8D2AB1D09CAF271\DataFiles { Action: 'Created', Type: 'REG_SZ', Contents: 'Server' }
*/




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: XML usage Pin
eblaschka12-Aug-14 4:42
eblaschka12-Aug-14 4:42 
GeneralRe: XML usage Pin
eblaschka12-Aug-14 11:14
eblaschka12-Aug-14 11:14 
AnswerThank you! Pin
eblaschka7-Aug-14 13:03
eblaschka7-Aug-14 13:03 
GeneralRe: Thank you! Pin
Dave Kreskowiak7-Aug-14 16:51
mveDave Kreskowiak7-Aug-14 16:51 
AnswerThank you! Pin
eblaschka7-Aug-14 15:49
eblaschka7-Aug-14 15:49 
GeneralRe: Thank you! Pin
Richard Deeming8-Aug-14 2:09
mveRichard Deeming8-Aug-14 2:09 
AnswerRe: XML usage Pin
PIEBALDconsult7-Aug-14 16:43
mvePIEBALDconsult7-Aug-14 16:43 
QuestionSend Email Notifications from Server Pin
Jassim Rahma6-Aug-14 11:28
Jassim Rahma6-Aug-14 11:28 
AnswerRe: Send Email Notifications from Server Pin
Bernhard Hiller6-Aug-14 20:54
Bernhard Hiller6-Aug-14 20:54 
GeneralRe: Send Email Notifications from Server Pin
Jassim Rahma10-Aug-14 10:19
Jassim Rahma10-Aug-14 10:19 
GeneralRe: Send Email Notifications from Server Pin
Bernhard Hiller10-Aug-14 20:06
Bernhard Hiller10-Aug-14 20:06 

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.