Click here to Skip to main content
15,888,286 members
Home / Discussions / C#
   

C#

 
GeneralRe: Calculate Plus Minus values from TextBox Pin
OriginalGriff23-Feb-11 23:07
mveOriginalGriff23-Feb-11 23:07 
GeneralRe: Calculate Plus Minus values from TextBox Pin
Pravin Patil, Mumbai23-Feb-11 22:31
Pravin Patil, Mumbai23-Feb-11 22:31 
QuestionLINQ to xml query Pin
faheemnadeem23-Feb-11 18:34
faheemnadeem23-Feb-11 18:34 
AnswerRe: LINQ to xml query Pin
#realJSOP24-Feb-11 4:55
mve#realJSOP24-Feb-11 4:55 
QuestionHow to display a warning message in file uploading when the uploading file is open in user machine... Pin
Rocky2323-Feb-11 18:05
Rocky2323-Feb-11 18:05 
GeneralRe: How to display a warning message in file uploading when the uploading file is open in user machine... Pin
Wayne Gaylard23-Feb-11 22:20
professionalWayne Gaylard23-Feb-11 22:20 
GeneralRe: How to display a warning message in file uploading when the uploading file is open in user machine... Pin
Rocky2323-Feb-11 22:42
Rocky2323-Feb-11 22:42 
GeneralRe: How to display a warning message in file uploading when the uploading file is open in user machine... Pin
Wayne Gaylard23-Feb-11 22:52
professionalWayne Gaylard23-Feb-11 22:52 
Sorry for that, but in your case this won't work as the OpenFileDialog Locks the file itself, so the IOException will always be caught. I created a function like this

private bool FileInUse(string fileName)
        {            
            try
            {
                System.IO.FileStream fs = System.IO.File.OpenWrite(fileName);
                fs.Close();
                return true;
            }
            catch (IOException ex)
            {
                return false;
            }
        }


and then calling it like this

OpenFileDialog file1 = new OpenFileDialog();            
            if (file1.ShowDialog() == true) 
            {
                if (!FileInUse(file1.FileName))
                {
                    MessageBox.Show("Already Open");
                }
                else
                {
                    using (Stream str = file1.OpenFile())
                    {
                        TextReader reader = new StreamReader(str);
                        reader.ReadToEnd();
                        textBox1.Text = file1.FileName;
                        textBox1.IsEnabled = false;
                    }
                }
            }


but this only works if the file is locked by the application that opens it (such as Word), otherwise if the file is open in an application that doesn't lock the file (such as NotePad), this always returns true.
Questionc# Need help getting WPF window to draw behind desktop icons Pin
lanpartyes23-Feb-11 15:13
lanpartyes23-Feb-11 15:13 
AnswerRe: c# Need help getting WPF window to draw behind desktop icons Pin
SledgeHammer0123-Feb-11 18:13
SledgeHammer0123-Feb-11 18:13 
GeneralRe: c# Need help getting WPF window to draw behind desktop icons Pin
lanpartyes23-Feb-11 23:49
lanpartyes23-Feb-11 23:49 
Questionvb.net to c#.net Pin
David C# Hobbyist.23-Feb-11 14:49
professionalDavid C# Hobbyist.23-Feb-11 14:49 
AnswerRe: vb.net to c#.net Pin
RobCroll23-Feb-11 16:18
RobCroll23-Feb-11 16:18 
AnswerRe: vb.net to c#.net Pin
thatraja23-Feb-11 16:29
professionalthatraja23-Feb-11 16:29 
AnswerRe: vb.net to c#.net Pin
Pravin Patil, Mumbai23-Feb-11 23:49
Pravin Patil, Mumbai23-Feb-11 23:49 
QuestionQuestion about adding/removing account Pin
turbosupramk323-Feb-11 9:05
turbosupramk323-Feb-11 9:05 
AnswerRe: Question about adding/removing account Pin
GenJerDan23-Feb-11 9:42
GenJerDan23-Feb-11 9:42 
GeneralRe: Question about adding/removing account Pin
turbosupramk323-Feb-11 10:14
turbosupramk323-Feb-11 10:14 
GeneralRe: Question about adding/removing account Pin
GenJerDan23-Feb-11 10:38
GenJerDan23-Feb-11 10:38 
GeneralRe: Question about adding/removing account Pin
turbosupramk323-Feb-11 11:05
turbosupramk323-Feb-11 11:05 
GeneralRe: Question about adding/removing account Pin
GenJerDan23-Feb-11 11:08
GenJerDan23-Feb-11 11:08 
GeneralRe: Question about adding/removing account Pin
turbosupramk323-Feb-11 11:33
turbosupramk323-Feb-11 11:33 
GeneralRe: Question about adding/removing account Pin
GenJerDan24-Feb-11 3:33
GenJerDan24-Feb-11 3:33 
GeneralRe: Question about adding/removing account Pin
turbosupramk324-Feb-11 5:27
turbosupramk324-Feb-11 5:27 
AnswerRe: Question about adding/removing account Pin
SledgeHammer0123-Feb-11 10:29
SledgeHammer0123-Feb-11 10:29 

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.