Click here to Skip to main content
15,898,984 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: stores files for my project Pin
Luc Pattyn27-Feb-10 16:30
sitebuilderLuc Pattyn27-Feb-10 16:30 
GeneralRe: stores files for my project Pin
DaveyM6927-Feb-10 17:57
professionalDaveyM6927-Feb-10 17:57 
GeneralRe: stores files for my project Pin
DaveyM6928-Feb-10 6:47
professionalDaveyM6928-Feb-10 6:47 
GeneralRe: stores files for my project Pin
Luc Pattyn27-Feb-10 15:46
sitebuilderLuc Pattyn27-Feb-10 15:46 
GeneralRe: stores files for my project Pin
DaveyM6927-Feb-10 15:52
professionalDaveyM6927-Feb-10 15:52 
AnswerRe: stores files for my project Pin
Not Active28-Feb-10 1:54
mentorNot Active28-Feb-10 1:54 
AnswerRe: stores files for my project Pin
DaveyM6928-Feb-10 6:46
professionalDaveyM6928-Feb-10 6:46 
Questionversion control software Pin
Khan Olid Mannan27-Feb-10 8:38
Khan Olid Mannan27-Feb-10 8:38 
AnswerRe: version control software Pin
Kristian Sixhøj27-Feb-10 8:40
Kristian Sixhøj27-Feb-10 8:40 
AnswerRe: version control software Pin
Som Shekhar27-Feb-10 9:34
Som Shekhar27-Feb-10 9:34 
GeneralRe: version control software Pin
Khan Olid Mannan27-Feb-10 15:16
Khan Olid Mannan27-Feb-10 15:16 

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.