ICSharpCode.TextEditor.TextEditorControlBase.LoadFile C# (CSharp) Method

LoadFile() public method

Loads a file given by fileName
public LoadFile ( string fileName, bool autoLoadHighlighting, bool autodetectEncoding ) : void
fileName string The name of the file to open
autoLoadHighlighting bool Automatically load the highlighting for the file
autodetectEncoding bool Automatically detect file encoding and set Encoding property to the detected encoding.
return void
		public void LoadFile(string fileName, bool autoLoadHighlighting, bool autodetectEncoding)
		{
			using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) {
				LoadFile(fileName, fs, autoLoadHighlighting, autodetectEncoding);
			}
		}
		

Same methods

TextEditorControlBase::LoadFile ( string fileName ) : void
TextEditorControlBase::LoadFile ( string fileName, Stream stream, bool autoLoadHighlighting, bool autodetectEncoding ) : void

Usage Example

 public void loadSourceCodeFileIntoTextEditor(String fileToLoad, TextEditorControlBase tecTargetTextEditor)
 {
     fileToLoad = tryToResolveFileLocation(fileToLoad, this);
     //this.okThreadSync(delegate
     //ExtensionMethods.invokeOnThread((Control)this, () =>
     tecSourceCode.invokeOnThread(
         () =>
             {
                 try
                 {
                     partialFileViewMode = false;
                     lbPartialFileView.Visible = false;
                     tecSourceCode.Visible = true;
                     long iCurrentFileSize = Files_WinForms.getFileSize(fileToLoad);
                     if (iCurrentFileSize > (iMaxFileSize*1024))
                     {
                         PublicDI.log.error("File to load is too big: max is {0}k, this file is {1}k : {2}",
                                      iMaxFileSize,
                                      iCurrentFileSize/1024, fileToLoad);
                         loadPartialFileView(fileToLoad);
                     }
                     else
                     {
                         if (fileToLoad.extension(".h2"))
                         {
                             setPathToFileLoaded(fileToLoad);
                             setDocumentContents(H2.load(fileToLoad).SourceCode, fileToLoad, false);
                             setDocumentHighlightingStrategy("aa.cs");
                         }
                         else
                         {
                             tecTargetTextEditor.LoadFile(fileToLoad);
                         }
                         if (fileToLoad.extension(".o2"))
                         {
                             var realFileTypeToload = Path.GetFileNameWithoutExtension(fileToLoad);
                             tecSourceCode.Document.HighlightingStrategy =
                                 HighlightingStrategyFactory.CreateHighlightingStrategyForFile(realFileTypeToload);
                         }
                         lbSourceCode_UnsavedChanges.Visible = false;
                         btSaveFile.Enabled = false;
                         eFileOpen(fileToLoad);
                     }
                 }
                 catch (Exception ex)
                 {
                     PublicDI.log.error("in loadSourceCodeFileIntoTextEditor: {0}", ex.Message);
                 }
                 return default(object);
             });
 }