Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
C

Christian Wulff

@Christian Wulff
About
Posts
15
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Read XML values (attributes and elements) with C#
    C Christian Wulff

    Try that one, joining with subItems and adding a null item in the case that no subitem exists:

    public void Today3()
    {
    XDocument xDoc = XDocument.Load(@"C:\Results\XMLTry.xml");
    var q = from homeItem in xDoc.Descendants("HomeItem")
    from subItem in homeItem.Element("Item").Descendants("ItemNumber").Any () ? homeItem.Element("Item").Descendants("ItemNumber") : new List(){null}
    select new
    {
    Description=(string)homeItem.Element("Description"),
    Time = (string)homeItem.Element("Time"),
    Id=(int)homeItem.Attribute("id"),
    ItemId = subItem == null ? "" : (string)subItem.Attribute("id"),
    Name = subItem == null ? "" : (string)subItem.Element("Name"),
    ItemDescrip = subItem == null ? "" : (string)subItem.Element("ItemDescrip")
    };

            foreach (var item in q)
                Console.WriteLine(@"Description = {0}
    

    Time = {1}
    Id = {2}
    ItemId = {3}
    Name = {4}
    ItemDescrip = {5}
    --------------", item.Description, item.Time, item.Id, item.ItemId, item.Name, item.ItemDescrip);
    }

    C# csharp xml

  • Read XML values (attributes and elements) with C#
    C Christian Wulff

    In what kind of data structure do you need them in your program? Or do you just need to write them to the console? If so, in which format should it be written to the console? Can you give an example?

    C# csharp xml

  • WPF Rant
    C Christian Wulff

    _Maxxx_ wrote:

    For a complex control with many many panels, grids, lists etc. changing the layout is a nightmare - just negotiating the Xaml can be a nightmare because VS2010 takes so damn long to parse the Xaml (even when not displaying the view) that one loses the will to live waiting for it!

    My experience is that with MVVM, I don't have one complex control with many many panels, grids etc. because these are divided into some sub-controls. I choose to edit the XAML directly because for me it is easier that way and not because the designer is buggy. Same like I write HTML instead of using an HTML editor. But most of my WPF experience comes from VS 2012 and VS 2013, which are much faster and more responsive than VS 2010. I didn't want to start a religious war, just sharing my opinion that once I learned MVVM, I prefer WPF and XAML to WinForms and think it is easier :) Especially because I don't write much code-behind and don't need to subscribe to many control Events.

    The Lounge csharp css wpf game-dev question

  • Read XML values (attributes and elements) with C#
    C Christian Wulff

    I'm not 100% sure if I understand your question correctly, but I could generate your desired result with this function:

    public void Today3()
    {
    XDocument xDoc = XDocument.Load(@"C:\Results\XMLTry.xml");
    var q = from c in xDoc.Descendants("HomeItem")
    select new
    {
    Description=(string)c.Element("Description"),
    Time = (string)c.Element("Time"),
    Id=(int)c.Attribute("id")
    };

            foreach (var item in q)
                Console.WriteLine(@"sDescrip = {0}
    

    time = {1}
    Id = {2}", item.Description, item.Time, item.Id);
    }

    Basically reading the XML elements into an anonymous type and using that to display the result.

    C# csharp xml

  • WPF Rant
    C Christian Wulff

    What are you missing in the XAML editor? I prefer to write XAML instead of using the designer and I think it is faster than doing the same with WinForms in the WinForms designer. I can't see the "ridiculous verbosity of XAML". You write the properties which you would set in the property window for WinForms. If you have a look at the generated WinForms code, that is ridiculous verbosity.

    The Lounge csharp css wpf game-dev question

  • how do i delete lines from .txt file? "Urgent!"
    C Christian Wulff

    Does the second line (K412 and K413 in your example) always start with one letter and is followed only by digits? Will there never be Km413 or just 413?

    C# question career

  • how do i delete lines from .txt file? "Urgent!"
    C Christian Wulff

    andredani wrote:

    now it only deletes the lines hwo gets in use, right?

    Yes, it should only write the lines which are not used in the temp file (and therewith deleting the used lines).

    andredani wrote:

    can u help me with a counter for this: if subitem[0] and subitem[1] matches with a lines[idex +1] and a lines[idex +2] then calculate subitems[1] with +1.

    I'm not quite sure that i understand what you mean. Let's assume your file looks like (I added line numbers): # (line 1) 5 (line 2) 6 (line 3) 5 (line 4) 6 (line 5) Normally your SubItems would be filled like this: SubItems[0] = 5 SubItems[1] = 6 SubItems[3] = 5 SubItems[5] = 6 But because line 2 = line 4 and line 3 = line 5 you want to add 1 to SubItems[1], so that the SubItems are: SubItems[0] = 5 SubItems[1] = 7 (6 from line 3 + 1) SubItems[3] = 5 SubItems[5] = 6 Is that what you mean?

    C# question career

  • how do i delete lines from .txt file? "Urgent!"
    C Christian Wulff

    Hi, you can do that if you create a temporary file, copy only the lines which should not be deleted to that temp file and later overwrite the original file with the temp file. E.g:

    string tempFilename = System.IO.Path.GetTempFileName();
    using (StreamReader sr = new StreamReader(path1 + ""))
    using (StreamWriter sw = new StreamWriter(tempFilename))
    {
    while (sr.Peek() > 0)
    {
    line = sr.ReadLine();
    if (line == "#")
    {
    name = sr.ReadLine();
    nameAndJob = string.Concat(name);
    Job = string.Concat(name);
    if (list.ContainsKey(nameAndJob))
    {
    item1 = list[nameAndJob];
    item1 = list[Job];
    item1.SubItems[1].Text = sr.ReadLine();
    item1.SubItems[3].Text = sr.ReadLine();
    item1.SubItems[5].Text = sr.ReadLine();
    /////////// Can i delete this lines in .txt file
    }
    else
    {
    // Write the "#" line
    sw.WriteLine("#");
    // Write the name which was read above
    sw.WriteLine(name);
    // The next three lines will be written in the else block below
    }
    }
    else
    {
    sw.WriteLine(line);
    }
    }
    sw.Flush();
    }
    System.IO.File.Delete(path1 + "/personalpr.txt");
    System.IO.File.Move(tempFilename, path1 + "/personalpr.txt");

    I didn't test the code, but I think you want something like that.

    C# question career

  • WTFOTD
    C Christian Wulff

    But that should result in a compiler error because the variable s is not known outside the loop, shouldn't it?

    The Lounge database csharp asp-net mysql sql-server

  • accessing dictionary within another one?
    C Christian Wulff

    Just apply every operation to the inner dictionary to input[culture]:

    if(input.ContainsKey(culture))
    {
    if(input[culture].ContainsKey(innerDictionaryKey))
    {
    string theValueYouWant = input[culture][innerDictionaryKey];
    }
    }

    C# question tutorial

  • How to execute a PHP file from C# code
    C Christian Wulff

    Hi! I didn't test it, but according to this site you should be able to authenticate to a SMTP server in .NET 1.1. Hope this helps.

    C# csharp php dotnet sysadmin tools

  • Personal Version Control
    C Christian Wulff

    Hi! I use CVS and for the integration into Visual Studio the PushOK CVS SCC proxy. CVS is free and the PushOK proxy costs 24$, but if you don't need the integration into Visual Studio, you can use e.g. WinCVS which is free.

    The Lounge sysadmin collaboration tutorial question discussion

  • Ugh
    C Christian Wulff

    Ennis Ray Lynch, Jr. wrote:

    encrypted swap or maybe I will just load the sawp on a self-defeating ramdisk

    I'm not a linux expert, but AFAIK swap is a partition on the HD which will be used if there is not enough free space in the RAM, so putting swap on a ramdisk is senseless, isn't it?

    The Lounge linux security

  • Could not find installable ISAM
    C Christian Wulff

    Hi, try

    string str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\projects\empdata.xls;Extended Properties=""Excel 8.0"";";

    I use Office 2003, too, but only Excel 8.0 works for me.

    C# help

  • Windows ding on textbox
    C Christian Wulff

    You need to catch the control's KeyPress event and set the Handled property of the KeyPressEventArgs to true:

    private void comboBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    // Check if the user pressed enter (enter = 13)
    if (e.KeyChar == 13)
    e.Handled = true;
    }

    C# question database
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups