FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Multiple File Extentions in C#

 


umeshtangnu
Hey guys im working on some C# for the week The program i am making is a word processer. I have gotten it to save as a rich text file and i am using the savefile dialog. The extention is filld in by selecting the save file from a list. If i have only the one extention in the extentions selecton it works. if i have multiple ones however the extention does not fill in and you have to type it manualy.

This works:
Code:

public void SaveMyFile()
    {
         
   SaveFileDialog saveFile1 = new SaveFileDialog();

         
   saveFile1.DefaultExt = "*.rtf";
   saveFile1.Filter = "RTF Files|*.rtf";
                            
   if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
      saveFile1.FileName.Length > 0)
       {
      textBox.SaveFile(saveFile1.FileName, RichTextBoxStreamType.PlainText);
        }
   }

This does not:
Code:

public void SaveMyFile()
   {
      SaveFileDialog saveFile1 = new SaveFileDialog();

      saveFile1.DefaultExt = "*.rtf";
                saveFile1.Filter = "RTF Files|*.rtf"+
                "HTML Files (*.htm)|*.htm|";
                           

      if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
            saveFile1.FileName.Length > 0)
         {
         textBox.SaveFile(saveFile1.FileName, RichTextBoxStreamType.PlainText);
                       // I belive the above line is the problem but evry time i re write it it will not compile
         }
      }
dayveday
I think the problem is this line
Code:
saveFile1.Filter = "RTF Files|*.rtf"+
                "HTML Files (*.htm)|*.htm|";

From my memory (which is a little hazy at this time of the morning) you need to put the pipe symbol between every description and every extension (otherwise, how could it tell the *.rtf has finished and the description HTML has started?)

So you want something more like
Code:
saveFile1.Filter = "RTF Files|*.rtf|HTML Files|*.htm;*.html;*.xhtml;*.shtml";


That should work for you...
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.