Click here to Skip to main content
15,902,276 members
Home / Discussions / C#
   

C#

 
AnswerRe: High Light a part of PictureBox Pin
Christian Graus18-Sep-06 20:36
protectorChristian Graus18-Sep-06 20:36 
GeneralRe: High Light a part of PictureBox Pin
morteza5718-Sep-06 23:07
morteza5718-Sep-06 23:07 
GeneralRe: High Light a part of PictureBox Pin
Christian Graus18-Sep-06 23:15
protectorChristian Graus18-Sep-06 23:15 
QuestionCreating New string Line Pin
praveenqwe18-Sep-06 18:16
praveenqwe18-Sep-06 18:16 
AnswerRe: Creating New string Line Pin
stancrm18-Sep-06 20:11
stancrm18-Sep-06 20:11 
QuestionEMC (electronic Medical claim) Pin
sonicsqwirl18-Sep-06 17:19
sonicsqwirl18-Sep-06 17:19 
QuestionMidi to wave Pin
ahjiang18-Sep-06 16:33
ahjiang18-Sep-06 16:33 
QuestionRuntime Error -- Writing to a File (FileStreams) Pin
midnitrcr18-Sep-06 11:51
midnitrcr18-Sep-06 11:51 
I'm having trouble with the following bit of code which generates an error at runtime. (it compiles fine) I've been working with C# for a total of about 3 hrs now, so go easy. Smile | :)

Main Program:

namespace StealthLog<br />
{<br />
    static class Program<br />
    {<br />
        /// <summary><br />
        /// The main entry point for the application.<br />
        /// </summary><br />
        [STAThread]<br />
        static void Main()<br />
        {<br />
            string str = "test of write";<br />
<br />
            StreamWriter sw = StealthLog.LogMgr.NewLogFile();<br />
            StealthLog.LogMgr.LogToFile(sw, str);<br />
<br />
            Application.EnableVisualStyles();<br />
            Application.SetCompatibleTextRenderingDefault(false);<br />
            Application.Run(new Form1());<br />
        }<br />
<br />
<br />
    }<br />
}


LogManager Code:

namespace StealthLog<br />
{<br />
    class LogMgr<br />
    {<br />
        internal static void LogToFile(StreamWriter sw, string text)<br />
        {<br />
            sw.WriteLine(text);<br />
        }<br />
<br />
        internal static StreamWriter NewLogFile()<br />
        {<br />
            string headerString = DateTime.Now.ToString() + "---------------\n";<br />
            string fullFilePath = Settings.Default.LogDirectory.ToString() +<br />
                                  Settings.Default.LogFile.ToString();<br />
<br />
            if (File.Exists(fullFilePath))<br />
            {<br />
                using (StreamWriter sw = File.CreateText(fullFilePath))<br />
                {<br />
                    sw.WriteLine("test1");<br />
                    return sw;<br />
                }<br />
            } else {<br />
                using (StreamWriter sw = File.CreateText(fullFilePath))<br />
                {<br />
                    sw.WriteLine("test2");<br />
                    return sw;<br />
                }<br />
            }<br />
        }<br />
    }<br />
}


The problem is in the sw.WriteLine(text); in the LogToFile section.
AnswerRe: Runtime Error -- Writing to a File (FileStreams) Pin
Christian Graus18-Sep-06 12:46
protectorChristian Graus18-Sep-06 12:46 
GeneralRe: Runtime Error -- Writing to a File (FileStreams) Pin
midnitrcr19-Sep-06 5:17
midnitrcr19-Sep-06 5:17 
QuestionHow to hide horizontal scroll bar in listview Pin
amymarie318-Sep-06 11:51
amymarie318-Sep-06 11:51 
AnswerRe: How to hide horizontal scroll bar in listview Pin
amymarie319-Sep-06 9:08
amymarie319-Sep-06 9:08 
QuestionTreview Context menu shortcut keys Pin
Saamir18-Sep-06 9:58
Saamir18-Sep-06 9:58 
Questionerror 80040154 at instantiation of COM object Pin
mkrelli18-Sep-06 9:17
mkrelli18-Sep-06 9:17 
QuestionAdding data to an Array Pin
Saamir18-Sep-06 8:58
Saamir18-Sep-06 8:58 
AnswerRe: Adding data to an Array Pin
Guffa18-Sep-06 9:09
Guffa18-Sep-06 9:09 
QuestionShowing unused drive letters Pin
numbers1thru918-Sep-06 8:36
numbers1thru918-Sep-06 8:36 
AnswerRe: Showing unused drive letters Pin
Christian Graus18-Sep-06 12:47
protectorChristian Graus18-Sep-06 12:47 
QuestionVariable/Collection contents seems to change between calls Pin
jimbobmcgee18-Sep-06 8:16
jimbobmcgee18-Sep-06 8:16 
QuestionUnable to open shim database version registry key - v2.0.50727.00000 Pin
yarns18-Sep-06 6:40
yarns18-Sep-06 6:40 
AnswerRe: Unable to open shim database version registry key - v2.0.50727.00000 Pin
Rob Graham18-Sep-06 7:32
Rob Graham18-Sep-06 7:32 
QuestionConfirm Email Address Pin
yesufollower18-Sep-06 5:30
yesufollower18-Sep-06 5:30 
AnswerRe: Confirm Email Address Pin
Ed.Poore18-Sep-06 5:35
Ed.Poore18-Sep-06 5:35 
AnswerRe: Confirm Email Address Pin
Guffa18-Sep-06 6:07
Guffa18-Sep-06 6:07 
QuestionGUI optimization Pin
Scarsymmetry18-Sep-06 5:10
Scarsymmetry18-Sep-06 5:10 

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.