Mike Askew 131 Veteran Poster Featured Poster

Sorry for the delay in reply, this is off my phone so can't code.

You can Do this but will need another foreach loop between c the inner loop looking for documents and settings or users.

This would make it os proof :)

Think the code can be improved so will try tomorrow

Mike Askew 131 Veteran Poster Featured Poster

Have managed to do it using the following:

            string[] foldersFound = Directory.GetDirectories(@"C:\Users");

            foreach (string folder in foldersFound)
            {
                try
                {
                    string[] subFoldersFound = Directory.GetDirectories(folder);

                    foreach (string subfolder in subFoldersFound)
                    {
                        if (subfolder.Contains("\\Dropbox"))
                            Console.WriteLine(subfolder);
                    }
                }
                catch (UnauthorizedAccessException ex) { }
            }
Mike Askew 131 Veteran Poster Featured Poster

I'm after some advice really.

I wish to create an application for myself and a friend using DropBox as a means to store and sync a CSV with data in.

Is it possible to programatically search through a computers directory to locate folder called 'Dropbox' without hardcoding its location?

If so how would I go about this?

Thanks in advance,

Mike Askew 131 Veteran Poster Featured Poster

Ah glad to see its fixed, sorry I wasnt of use :)

Mike Askew 131 Veteran Poster Featured Poster

Have to say im stumped now. I would recommend StackOverflow as a possible site for finding a solution, that is what I use myself.

Mike Askew 131 Veteran Poster Featured Poster

It'll probably be the 'and', have you tried '&' instead?

Mike Askew 131 Veteran Poster Featured Poster

It was going to help in terms of being able to run the xslt code itself on my machine, however its still looking for the common.xsl for import which is causing the error in compiling.

Trying to figure out how to point to the last one only, my initial thoughts would be to use a template to call two versions of your current template, one that selects the first instance, and the second, the last instance. However having issues matching the last instance using a variable set to the value of node count.

Need to find a way around that :/

Mike Askew 131 Veteran Poster Featured Poster

Input XML

<?xml version="1.0" encoding="UTF-8"?>
<Employer>
  <Employees>
    <EmployeesDetails>van ind 26%</EmployeesDetails>
  </Employees>
  <Employees>
    <EmployeesDetails>van ind</EmployeesDetails>
  </Employees>
</Employer>

XSLT Sheet

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent ="yes"/>
  <xsl:strip-space elements ="*"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="EmployeesDetails/text()" name="tokenize">
    <xsl:param name="text" select="."/>
    <xsl:param name="separator" select="' '"/>
    <xsl:param name="nodename">Names</xsl:param>
    <xsl:choose>
      <xsl:when test="not(contains($text, $separator))">
        <xsl:choose>
          <xsl:when test="(contains($text, '%'))">
            <xsl:element name ="Weather">
              <xsl:value-of select="normalize-space(substring-before($text, '%'))"/>
            </xsl:element>
          </xsl:when>
          <xsl:otherwise>
            <xsl:element name ="{$nodename}">
              <xsl:value-of select="normalize-space($text)"/>
            </xsl:element>
            <xsl:element name="Weather">100</xsl:element>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:element name ="{$nodename}">
          <xsl:value-of select="normalize-space(substring-before($text, $separator))"/>
        </xsl:element>
        <xsl:call-template name="tokenize">
          <xsl:with-param name="text" select="substring-after($text, $separator)"/>
          <xsl:with-param name ="nodename">Location</xsl:with-param>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

Output

<?xml version="1.0" encoding="utf-8"?>
<Employer>
  <Employees>
    <EmployeesDetails>
      <Names>van</Names>
      <Location>ind</Location>
      <Weather>26</Weather>
    </EmployeesDetails>
  </Employees>
  <Employees>
    <EmployeesDetails>
      <Names>van</Names>
      <Location>ind</Location>
      <Weather>100</Weather>
    </EmployeesDetails>
  </Employees>
</Employer>

Splitting a string into new nodes is not simple in XSLT 1.0, it requires a recursive function, it is further complicated by the element naming requirements and so this function is tailor written for those three names alone.

Mike Askew 131 Veteran Poster Featured Poster
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes"/>

  <xsl:variable name ="urlVar"></xsl:variable>
  <xsl:variable name="title"></xsl:variable>

  <xsl:template match="*">
    <xsl:element name="td">
      <xsl:element name="a">
        <xsl:attribute name="href">
          <xsl:value-of select ="$urlVar"/>
        </xsl:attribute>
        <xsl:value-of select="$title"/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  </xsl:stylesheet>

I've produced what your after using this code. It is worth noting that if you enable Indenting in the stylesheet it wont give the flat look you are after.

Mike Askew 131 Veteran Poster Featured Poster

Can we see your full XSLT, can't edit it currently due to missing declarations allowing the functionality.

Mike Askew 131 Veteran Poster Featured Poster

I think it would be done by clearing the line and redrawing in the new position, say incrementing the x co-ord by 1 to move it right.

Not entirely sure thats the only way though.

Mike Askew 131 Veteran Poster Featured Poster

No worries, mark thread as solved if nothing else needs fixing :)

Mike Askew 131 Veteran Poster Featured Poster

I have achieved the desired using the following (Apologies for time delay i've never had to do C# to XML before :D, Presuming your using C# ofc forgot to ask that >.<)

static void Main()
        {
            DataTable table = GetTable();

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(@"FilePathHere", settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("Data");

                string currentManager = "";
                int currentTotal = 0;

                List<String> lstManagerCounts = new List<String>();
                foreach (DataRow row in table.Rows) //Get unique managerID's and their totals into a list
                {
                    if (currentManager != row.ItemArray[0].ToString())
                    {
                        if (currentManager != "")
                            lstManagerCounts.Add(string.Format("{0},{1}", currentManager, currentTotal));

                        currentManager = row.ItemArray[0].ToString();
                        currentTotal = 0;
                    }
                    currentTotal += (int)row.ItemArray[2];
                }
                lstManagerCounts.Add(string.Format("{0},{1}", currentManager, currentTotal));

                foreach (string entry in lstManagerCounts) //Loop the unique ManagerId's finding related entries and listing them
                {
                    string ManagerID = entry.Substring(0, entry.IndexOf(','));
                    string Total = entry.Substring(entry.IndexOf(',')+1);

                    writer.WriteStartElement(ManagerID);
                    writer.WriteAttributeString("Total", Total);

                    foreach (DataRow dRow in table.Rows)
                    {
                        if (dRow.ItemArray[0].ToString() == ManagerID)
                        {
                            writer.WriteStartElement(dRow.ItemArray[1].ToString());
                            writer.WriteAttributeString("Value", dRow.ItemArray[2].ToString());
                            writer.WriteEndElement();
                        }
                    }
                    writer.WriteEndElement();
                }
                writer.WriteEndDocument();
            }
        }

        static DataTable GetTable() //Setting up the datatable using provided example data
        {
            DataTable table = new DataTable();
            table.Columns.Add("ManagerID", typeof(string));
            table.Columns.Add("VendorID", typeof(string));
            table.Columns.Add("Count", typeof(int));
            table.Rows.Add("M1", "V1", 10);
            table.Rows.Add("M1", "V2", 5);
            table.Rows.Add("M2", "V1", 10);
            table.Rows.Add("M2", "V2", 5);
            table.Rows.Add("M3", "V1", 10);
            table.Rows.Add("M3", "V2", 5);
            return table;
        }

It works by looking through the data in a prelim, identifying all unique manager ID's and getting the totals of their entries (as XMLWriter is forwards only).

I then re-loop through the table matching the ManagerID's and creating nodes if they match, else …

Mike Askew 131 Veteran Poster Featured Poster

You haven't said how you want the XML laid out, nobody can help without that information.

Ie.

<M1 Total='15'>
    <V1 Value='10' />
    <V2 Value='5' />
</M1>

Or.

<M1>
    <Total>15</Total>
    <V1>
        <Value>10</Value>
    </V1>
    <V2>
        <Value>5</Value>
    </V2>
</M1>
Mike Askew 131 Veteran Poster Featured Poster

Your class doesn't currently contain what is asked for, nor contain a constructor, they are looking for the following:

public class Employee
{
    private string firstName;
    private string lastName;
    private double wage;

    public Employee (string FName, string LName, double WageGiven) //The constructor
    {
        FirstName = FName;
        LastName = LName;
        Wage = WageGiven;
    }

    public string FirstName
    {
        get { return firstName; }
        set { firstName = value; }
    }

    public string LastName
    {
        get { return lastName; }
        set { lastName = value; }
    }

    public double Wage
    {
        get { return wage; }
        set { if(value >= 0.0) { wage = value; } } //Your value checking was wrong here
    }
}

Which you can then implement in the following way:

//Create the employees using the new constructors we have
Employee EmpOne = new Employee("Joe", "Bloggs", 1000);
Employee EmpTwo = new Employee("Jimi", "Hendrix", 2000);
Employee EmpThree = new Employee("Calvin", "Harris", -100); //Nothing should happen in terms of wage for this guy

//Show Wages
Console.WriteLine("Wages: EmployeeOne-£{0}, EmployeeTwo-£{1}, EmployeeThree-£{2}", EmpOne.Wage, EmpTwo.Wage, EmpThree.Wage);

//Increase Wages
EmpOne.Wage = EmpOne.Wage * 1.10;
EmpTwo.Wage = EmpTwo.Wage * 1.10;
EmpThree.Wage = EmpThree.Wage * 1.10;

//Show New Wages
Console.WriteLine("Wages: EmployeeOne-£{0}, EmployeeTwo-£{1}, EmployeeThree-£{2}", EmpOne.Wage, EmpTwo.Wage, EmpThree.Wage);

Hope that helps :)

Mike Askew 131 Veteran Poster Featured Poster

Can you provide some example code of where you dont understand/are having trouble with :)

Mike Askew 131 Veteran Poster Featured Poster

Set the valuemember to the ID value.
Set the displaymember to the Name value.

Then use the valuemember instead of displaymember when writing the SQL to store it.

Mike Askew 131 Veteran Poster Featured Poster
Mike Askew 131 Veteran Poster Featured Poster

For others information,

What database are you using? Oracle? SQLServer? Access?

Mike Askew 131 Veteran Poster Featured Poster

Stackoverflow

Mike Askew 131 Veteran Poster Featured Poster

Well in terms of handling the account number and surname search possibilities, you can use a TryParse to distinguish which you are dealing with, I am assuming an account number is entirely numeric.

string InputFromTextBox = "0011223344";
int OutputAccountNumber;

// if bool = true, its account number, else false, surname
bool IsAccountNumber = int32.TryParse(InputFromTextBox, out OutputAccountNumber);
Mike Askew 131 Veteran Poster Featured Poster

If it seems to happen in future I shall do so :)

Just wondered if that would be the case as to why we seem to have quite a few people in the xslt forum who post a question and disappear, of course this could just be coincedence (more than likely)

Mike Askew 131 Veteran Poster Featured Poster

It wasnt at the time. This was a while ago and so im wondering what the default is now (in-case youve looked at my most recent posts, which kind of sparked the topic)

Seeing alot in the XSLT forum of people posting a question, answering and not hearing back and wondered, as they all seem to be new joiners usually, if the email subscription is off by default and so dont bother to check back due to the few days on the reply usually.

Mike Askew 131 Veteran Poster Featured Poster

More of a question than feedback if im honest, as i'm not sure if it was just me or not.

But I noticed after a while I wasnt getting the emails from threads I had replied to, obviously indicating the auto subscribe to topics I reply to was turned off.

Is this the default setting? Or just my mishap.

Mike Askew 131 Veteran Poster Featured Poster

Xslt:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="info">
    <xsl:copy>
      <xsl:element name="content">
        <xsl:for-each select="content">
          <xsl:apply-templates select="@*"/>
          <xsl:apply-templates select="node()"/>
        </xsl:for-each>
      </xsl:element>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Applied to the given XML produces:

<xml>
  <head>
    <info>
      <content>
        <source attribute1="RSC1985s5c1" attribute2="6(17)">
          data1
        </source>
        <cite />
        <case />
        (
        <target attribute1="LRC1985s5c1" attribute2="6(17)1">
          3e/191
        </target>
        )
      <source attribute1="RSC1985s5c1" attribute2="6(17)">
          data2
        </source><cite /><case />
        (
        <target attribute1="LRC1985s5c4" attribute2="6(17)1">
          4e/54
        </target>
        )
      </content>
    </info>
  </head>
</xml>

There is no standard for how indentation is dealt with and so the odd indentation on some elements may not be the same on your xslt processor. The format you desired however is achieved.

Credit goes to Dimitre Novatchev on StackOverflow for solving my issue I had when doing this.

Mike Askew 131 Veteran Poster Featured Poster

Ok, working on it currently, have my own little issue with it which im looking for a solution too and then its done :)

Mike Askew 131 Veteran Poster Featured Poster
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.w3.org/1999/xhtml" version="1.0">
  <xsl:template match="/*">
    <xsl:value-of select="x:body/x:div/x:p"/> //note changes to this line
  </xsl:template>
</xsl:stylesheet>

I've assigned the HTML namespace to x, so now we prefix all references to the XML with x: and then you can find the nodes you were missing before :)

Proof in action:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.w3.org/1999/xhtml" version="1.0">
  <xsl:template match="/*">
    <xsl:value-of select="x:body/x:div/x:p"/>
  </xsl:template>
</xsl:stylesheet>

run on

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
  </head>
  <body class="3-column">
    <div class="centercol">
      <p>Hello world</p>
    </div>
    <div class="leftcol">
      <div id="menu">
      </div>
    </div>
    <div class="rightcol"> </div>
  </body>
</html>

gives:

<?xml version="1.0" encoding="utf-8"?>Hello world
Mike Askew 131 Veteran Poster Featured Poster

Try This.

The xmlns will be an attribute of the <pierRecord> element.

Mike Askew 131 Veteran Poster Featured Poster

Can you make it more clear the format of the input, and the exact format of the output, and something can be looked into. A JSON format currently means nothing to me but doesnt mean XSLT cant be made :)

Mike Askew 131 Veteran Poster Featured Poster

What exactly are the brackets for in the xml? are they typos? i.e.

(
<target attribute1="LRC1985s5c4" attribute2="6(17)1">
4e/54
</target>
)
Mike Askew 131 Veteran Poster Featured Poster
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="person">
    <xsl:if test="id = 677">
      <xsl:element name="Output">
        <xsl:value-of select="name"/>
      </xsl:element>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

As an example.

We would use the xsl:if to recreate the same if statement you demonstrated in c# :)

Mike Askew 131 Veteran Poster Featured Poster
          <xsl:for-each select="Score">
            <xsl:element name="tem:arg0">
              <xsl:value-of select='format-number(.,"#" )'/>
            </xsl:element>
          </xsl:for-each>

You've already selected score in the for-each and so it is looked for a child of score called score, changing this to . means it selects current which is in fact the value you are looking for :)

Mike Askew 131 Veteran Poster Featured Poster

No worries

Mike Askew 131 Veteran Poster Featured Poster

Hmmm, well you couldnt use a variable inside the app to store which number it is adding to the file as each instance of the application would have it own version of this variable.

Could check the file name of the log files found, get the highest number (if there is one) and then increment that by one to get the new name.

So for example if log1 exists it would make log2.

Easily done with a bit of RegEx :)

Personally, if I were you I'd have each app write to a log file of its own regardless of whether the first is in use, as it would seem cleaner. But thats my opinion.

Mike Askew 131 Veteran Poster Featured Poster

One note about GeissT's submission, if used ensure you use a Thread.Sleep() in that loop to avoid just using your CPU constantly on that loop.

Mike Askew 131 Veteran Poster Featured Poster

Method which checks if it can open the file to write and if it can signals that the file is not in use. Else catches the exception caused and flags file as in use.

public bool CheckFileInUse(string File)
{
    bool success = false;
    try
    {
        FileStream fileStream;
        using (fileStream = new FileStream(File, FileMode.Open, FileAccess.Write)
        {

        }
        fileStream.Close()
        success = false;
    }
    catch (IOException exn)
    {
        if(ex.Message.ToString().Contains("The process cannot access the file")
        {
            success = true;
        }
    }
    //True = in use, False = not in use
    return success;
}
Mike Askew 131 Veteran Poster Featured Poster

Fine, I would create a uniquely identified log for each instance of the program.

However have found this which might provide some insight into how to do it, look at the selected answer on it.

Mike Askew 131 Veteran Poster Featured Poster

I would create a log file for both programs, im not aware of a way to write simultaneously to log files. Perhaps one of the more experienced members of the forum does?

Mike Askew 131 Veteran Poster Featured Poster

Could we see the full XML structure your using?

Also an array wouldnt change order unless you changed the order programatically.

Mike Askew 131 Veteran Poster Featured Poster

Its finally done, quite basic but shows the concepts of using the random class to create a tournament.

Points to note about the code below:
- Tournament plays only 20 games
- There is no validation in terms of all teams playing even amounts of matches
- Its very basic :)

Hopefully though it'll give you an idea on how the random class can be used.

namespace ScorerApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Tournament theTournment = new Tournament();
            theTournment.PlayMatches();
            Console.WriteLine();
            theTournment.GetTournamentOutcome();
            Console.ReadLine();
        }
    }

    class Team : IComparable
    {
        private string teamName;
        private string teamCaptain;
        private int points;

        int IComparable.CompareTo(object obj)
        {
            Team team = (Team)obj;

            if (this.Points > team.Points)
                return -1;
            else
                if (this.Points == team.Points)
                    return 0;
                else
                    return 1;
        }

        public Team(string TeamName, string TeamCaptain)
        {
            teamName = TeamName;
            teamCaptain = TeamCaptain;
        }

        public void AddPoints(int PointsToAdd)
        {
            points += PointsToAdd;
        }

        public int Points { get { return points; } }
        public string TeamName { get { return teamName; } }
        public string TeamCaptain { get { return teamCaptain; } }

    }

    class Match
    {
        public Team[] teamsPlaying = new Team[2];
        public int pointsWon { get; private set; }

        private int[] possiblePoints = new int[3] { 0, 1, 3 };
        private Random rnd = new Random();

        public Match(Team HomeTeam, Team AwayTeam)
        {
            teamsPlaying[0] = HomeTeam;
            teamsPlaying[1] = AwayTeam;
        }

        public Team PlayMatch(out int PointsWon)
        {
            pointsWon = possiblePoints[rnd.Next(0,2)];

            PointsWon = pointsWon;
            return teamsPlaying[rnd.Next(0,1)];
        }
    }

    class Tournament
    { …
Mike Askew 131 Veteran Poster Featured Poster

Agree with Mitja, I'll write a bit of team code and it'll be up tonight regardless of what you want, gives me something to do :)

Mike Askew 131 Veteran Poster Featured Poster

You want it like football scores?

Could do this then for each "match fixture"

Random rnd = new Random();
int[] availablePoints = new int[3] { 0, 1, 3 }

points = availablePoints[rnd.Next(0,2)];

Giving a random result of either 0 1 or 3 when applied to the array :)

Edit: If no one beats me to it i'll make a match fixture thing tonight when back from work

Mike Askew 131 Veteran Poster Featured Poster

There was no mention of it being football related :)

Mike Askew 131 Veteran Poster Featured Poster

From what I understand Mitja, it is used to randomly generate a points total for each of the seven teams specified, hence the team having an int points;

:)

Mike Askew 131 Veteran Poster Featured Poster

Well, this is how to use the Random class and Next(int a, int b,)

Random rnd = new Random()

//Generates a random number between 0 and 10
points = rnd.Next(0,10);

So you could give the team a method which when called uses the above to generate a points score for them? Obviously changing the upper and lower bounds as you see fit.

MSDN: Here

Mike Askew 131 Veteran Poster Featured Poster

So what exactly do you need help with?

Mike Askew 131 Veteran Poster Featured Poster

Glad it did, dont forget to make the thread as solved!

Mike Askew 131 Veteran Poster Featured Poster

Here's an XSLT Stylesheet:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:cs="urn:cs"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="cs">

  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />

  <msxsl:script language="C#" implements-prefix="cs">
    <![CDATA[
      public string GetCurrentDateTime(string name)
     {
        string filename = name.Substring(0, name.IndexOf('.'));
        string extension = name.Substring(name.IndexOf('.'));

        return(filename + "_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + extension);
     }
     ]]>
  </msxsl:script>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="attachment">
    <xsl:variable name="vAttachment" select="."></xsl:variable>
    <xsl:element name="attachment">
      <xsl:attribute name="type">
        <xsl:value-of select="$vAttachment/@type"/>
      </xsl:attribute>
      <xsl:attribute name="name">
        <xsl:value-of select="cs:GetCurrentDateTime($vAttachment/@name)"/>
      </xsl:attribute>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>

That when run on:

<node name="testEmail" type="emailoutput" subject="this is a test mail with an attachment" xsl="--" outputType="text/plain" >
  <attachment type="text/plain" name="test.dat"/>
</node>

Produces:

<node name="testEmail" type="emailoutput" subject="this is a test mail with an attachment" xsl="--" outputType="text/plain">
  <attachment type="text/plain" name="test_23052012120054.dat" />
</node>

DateTime of run: 23/05/2012 at 12:00:54pm

Hope this helps!

Mike Askew 131 Veteran Poster Featured Poster

Aah yes i see now, skimmed over a couple of the lines which made it look like it wouldnt work :)

Mike Askew 131 Veteran Poster Featured Poster

I must say though Freedom, i'm looking at the Grade class and it is so confusing as to what its doing :)