Click here to Skip to main content
15,889,116 members
Home / Discussions / C#
   

C#

 
GeneralRe: c# back up program ? :S Pin
booo2222222222222217-Sep-09 12:13
booo2222222222222217-Sep-09 12:13 
GeneralRe: c# back up program ? :S Pin
EliottA17-Sep-09 12:16
EliottA17-Sep-09 12:16 
GeneralRe: c# back up program ? :S Pin
booo2222222222222217-Sep-09 12:21
booo2222222222222217-Sep-09 12:21 
GeneralRe: c# back up program ? :S Pin
Richard MacCutchan17-Sep-09 23:03
mveRichard MacCutchan17-Sep-09 23:03 
AnswerRe: c# back up program ? :S Pin
Vimalsoft(Pty) Ltd17-Sep-09 20:45
professionalVimalsoft(Pty) Ltd17-Sep-09 20:45 
Questionforeach simple question Pin
JollyMansArt17-Sep-09 10:14
JollyMansArt17-Sep-09 10:14 
AnswerRe: foreach simple question Pin
Ian Shlasko17-Sep-09 10:28
Ian Shlasko17-Sep-09 10:28 
QuestionRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:04
JollyMansArt17-Sep-09 12:04 
I appreciate everyone's help here.
To get a better Idea of what I am really trying to do is this:

I receive a path that in a string.
The path contains %USERNAME% in it.
So I need to convert the %USERNAME% to the users login name that windows identifies say "mgeorge"

So in the example c:\apple\%username%\MDB
would become: C:\apple\mgeorge\MDB

Which if I was using dos scripts this would easily work.
But I can't find a easy way of doing this conversion. If there is a simpler way please help me understand.
So I decided I could do something like this as my work around.


I would create a list...

private List<string> IO_SystemVariables()<br />
            {<br />
                List<string> IO_SystemVariables = new List<string>();<br />
                IO_SystemVariables.Add("%USERNAME%");<br />
                IO_SystemVariables.Add(Environment.UserName.ToString());<br />
                IO_SystemVariables.Add("%MACHINENAME%");<br />
                IO_SystemVariables.Add(Environment.MachineName.ToString());<br />
                return IO_SystemVariables;<br />
            }<br />



The loop thru that list to apply the changes to the string
say something like this:



private static string IO_CheckForSystemVariablePath(String MyPath)<br />
            {<br />
                List<string> io_SystemVariables = IO_SystemVariables();<br />
                for (int i = 0; i < io_SystemVariables.Count; i += 2)<br />
                {<br />
                    if (MyPath.IndexOf(io_SystemVariables[i], 0) > 0)<br />
                    {<br />
                        return MyPath.Replace(io_SystemVariables[i],io_SystemVariables[i + 1];<br />
                    }<br />
                    <br />
                }<br />
                <br />
            }


Well the code should be close enough to what I was trying to do.
Since every the list 0,2,4,etc will be a variable and the 1,2,5,etc will be it's conversion I figured I would experiment with the foreach loop that I never have been able to figure out.
But if there is an even better way of handling this issue than what I have layed out I am all ears.
AnswerRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 12:08
mvePIEBALDconsult17-Sep-09 12:08 
QuestionRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:15
JollyMansArt17-Sep-09 12:15 
QuestionRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:22
JollyMansArt17-Sep-09 12:22 
AnswerRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 13:06
mvePIEBALDconsult17-Sep-09 13:06 
AnswerRe: foreach simple question Pin
Ian Shlasko17-Sep-09 12:21
Ian Shlasko17-Sep-09 12:21 
AnswerRe: foreach simple question Pin
Luc Pattyn17-Sep-09 12:21
sitebuilderLuc Pattyn17-Sep-09 12:21 
AnswerRe: foreach simple question Pin
Christian Graus17-Sep-09 10:28
protectorChristian Graus17-Sep-09 10:28 
AnswerRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 10:32
mvePIEBALDconsult17-Sep-09 10:32 
GeneralRe: foreach simple question Pin
Christian Graus17-Sep-09 12:03
protectorChristian Graus17-Sep-09 12:03 
GeneralRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 12:05
mvePIEBALDconsult17-Sep-09 12:05 
GeneralRe: foreach simple question Pin
Christian Graus17-Sep-09 12:09
protectorChristian Graus17-Sep-09 12:09 
GeneralRe: foreach simple question Pin
Ian Shlasko17-Sep-09 12:30
Ian Shlasko17-Sep-09 12:30 
GeneralRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:36
JollyMansArt17-Sep-09 12:36 
GeneralRe: foreach simple question Pin
PIEBALDconsult17-Sep-09 13:35
mvePIEBALDconsult17-Sep-09 13:35 
GeneralRe: foreach simple question Pin
JollyMansArt17-Sep-09 12:09
JollyMansArt17-Sep-09 12:09 
AnswerRe: foreach simple question Pin
Not Active17-Sep-09 13:26
mentorNot Active17-Sep-09 13:26 
Questiongood books for XML With windows c# Pin
santosh_anu17-Sep-09 9:44
santosh_anu17-Sep-09 9:44 

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.