Click here to Skip to main content
15,911,762 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sliding panels Pin
Luc Pattyn27-Feb-10 23:41
sitebuilderLuc Pattyn27-Feb-10 23:41 
AnswerRe: Sliding panels Pin
Wamuti27-Feb-10 23:49
Wamuti27-Feb-10 23:49 
GeneralRe: Sliding panels Pin
OriginalGriff28-Feb-10 0:26
mveOriginalGriff28-Feb-10 0:26 
AnswerMessage Closed Pin
28-Feb-10 1:01
stancrm28-Feb-10 1:01 
GeneralRe: Sliding panels Pin
Wamuti28-Feb-10 1:18
Wamuti28-Feb-10 1:18 
QuestioncheckedListBox problem Pin
Gali197827-Feb-10 20:23
Gali197827-Feb-10 20:23 
AnswerRe: checkedListBox problem Pin
Khaniya27-Feb-10 22:07
professionalKhaniya27-Feb-10 22:07 
AnswerRe: checkedListBox problem Pin
DX Roster4-Mar-10 18:52
DX Roster4-Mar-10 18:52 
QuestionwebBrowser and webRequest work in IDE but not from desktop [modified] Pin
BarnabyByrne27-Feb-10 13:34
BarnabyByrne27-Feb-10 13:34 
AnswerRe: webBrowser and webRequest work in IDE but not from desktop Pin
Luc Pattyn27-Feb-10 13:53
sitebuilderLuc Pattyn27-Feb-10 13:53 
GeneralRe: webBrowser and webRequest work in IDE but not from desktop [modified] Pin
BarnabyByrne27-Feb-10 14:21
BarnabyByrne27-Feb-10 14:21 
GeneralRe: webBrowser and webRequest work in IDE but not from desktop Pin
BarnabyByrne27-Feb-10 16:32
BarnabyByrne27-Feb-10 16:32 
QuestionDeturmining when a html form has been submitted [modified] Pin
tyjnfghnfgsdf27-Feb-10 10:13
tyjnfghnfgsdf27-Feb-10 10:13 
Questionstores files for my project Pin
jogisarge27-Feb-10 9:05
jogisarge27-Feb-10 9:05 
AnswerRe: stores files for my project Pin
AspDotNetDev27-Feb-10 11:43
protectorAspDotNetDev27-Feb-10 11:43 
AnswerRe: stores files for my project [modified] Pin
DaveyM6927-Feb-10 14:50
professionalDaveyM6927-Feb-10 14:50 
AnswerRe: stores files for my project Pin
Luc Pattyn27-Feb-10 14:59
sitebuilderLuc Pattyn27-Feb-10 14:59 
GeneralRe: stores files for my project Pin
DaveyM6927-Feb-10 15:01
professionalDaveyM6927-Feb-10 15:01 
GeneralRe: stores files for my project [modified] Pin
DaveyM6927-Feb-10 15:16
professionalDaveyM6927-Feb-10 15:16 
This works for me...

Test Code:
C#
using System;
using System.IO;

namespace ConsoleApplication
{
    class Program
    {
        public static readonly string UserPath = 
            Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        public static readonly string AllUsersPath = 
            Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);

        static void Main(string[] args)
        {
            try
            {
                string fileName = "Test.txt";
                string textToSave = "AbcDefGhi";

                string userFilePath = Path.Combine(UserPath, fileName);
                string allUsersFilePath = Path.Combine(AllUsersPath, fileName);

                using (TextWriter userTextWriter = new StreamWriter(userFilePath),
                allUsersTextWriter = new StreamWriter(allUsersFilePath))
                {
                    Console.WriteLine("Writing {0} to {1}", textToSave, userFilePath);
                    userTextWriter.WriteLine(textToSave);
                    Console.WriteLine("Writing {0} to {1}", textToSave, allUsersFilePath);
                    allUsersTextWriter.WriteLine(textToSave);
                }

                using (TextReader userTextReader = new StreamReader(userFilePath),
                allUsersTextReader = new StreamReader(allUsersFilePath))
                {
                    Console.WriteLine("Reading from {0}", userFilePath);
                    Console.WriteLine(userTextReader.ReadLine());
                    Console.WriteLine("Reading from {0}", allUsersFilePath);
                    Console.WriteLine(allUsersTextReader.ReadLine());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.ReadKey();
        }
    }
}

[Edit] Added exception checking [/Edit]
[Edit2] Removed inner exception log as per Luc's post below [/Edit2]
Dave

Tip: Passing values between objects using events (C#)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

modified on Saturday, February 27, 2010 9:51 PM

GeneralRe: stores files for my project Pin
Luc Pattyn27-Feb-10 15:23
sitebuilderLuc Pattyn27-Feb-10 15:23 
GeneralRe: stores files for my project Pin
DaveyM6927-Feb-10 15:30
professionalDaveyM6927-Feb-10 15:30 
GeneralRe: stores files for my project Pin
DaveyM6927-Feb-10 15:39
professionalDaveyM6927-Feb-10 15:39 
GeneralRe: stores files for my project Pin
Luc Pattyn27-Feb-10 15:45
sitebuilderLuc Pattyn27-Feb-10 15:45 
GeneralRe: stores files for my project Pin
DaveyM6927-Feb-10 15:50
professionalDaveyM6927-Feb-10 15:50 
GeneralRe: stores files for my project Pin
DaveyM6927-Feb-10 15:59
professionalDaveyM6927-Feb-10 15:59 

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.