当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.FileInfo.Open方法代码示例

本文整理汇总了C#中System.IO.FileInfo.Open方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileInfo.Open方法的具体用法?C# System.IO.FileInfo.Open怎么用?C# System.IO.FileInfo.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileInfo的用法示例。


在下文中一共展示了System.IO.FileInfo.Open方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: writeToFileF64

        /// <summary>
        /// Writes the current terrain heightmap to disk, in the format of a 65536 entry double[] array.
        /// </summary>
        /// <param name="filename">The desired output filename</param>
        public void writeToFileF64(string filename)
        {
            System.IO.FileInfo file = new System.IO.FileInfo(filename);
            System.IO.FileStream s = file.Open(System.IO.FileMode.CreateNew, System.IO.FileAccess.Write);
            System.IO.BinaryWriter bs = new System.IO.BinaryWriter(s);

            int x, y;
            for (x = 0; x < w; x++)
            {
                for (y = 0; y < h; y++)
                {
                    bs.Write(heightmap.get(x,y));
                }
            }

            bs.Close();
            s.Close();
        }
开发者ID:BackupTheBerlios,项目名称:ulife-svn,代码行数:22,代码来源:TerrainEngine.cs

示例2: writeFile

        public static void writeFile(String logMessage)
        {

            System.IO.FileStream fileStream = null;
            System.IO.StreamWriter sr = null;
            try
            {
                DateTime dt = DateTime.Now;
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(_logFile);
                if (!fileInfo.Exists)
                {
                    fileStream = fileInfo.Open(System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
                    sr = new System.IO.StreamWriter(fileStream);
                }
                else
                {
                    sr = fileInfo.AppendText();
                }


                sr.Write(logMessage);

            }
            catch (Exception ex)
            {

            }
            finally
            {
                if (sr != null)
                    sr.Close();
                if (fileStream != null)
                    fileStream.Close();

            }
        }
开发者ID:Geoneer,项目名称:pdok-extensie,代码行数:36,代码来源:Utils.cs

示例3: loadFromFileF64

        /// <summary>
        /// Loads a file consisting of 256x256 doubles and imports it as an array into the map.
        /// </summary>
        /// <remarks>TODO: Move this to libTerrain itself</remarks>
        /// <param name="filename">The filename of the double array to import</param>
        public void loadFromFileF64(string filename)
        {
            System.IO.FileInfo file = new System.IO.FileInfo(filename);
            System.IO.FileStream s = file.Open(System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader bs = new System.IO.BinaryReader(s);
            int x, y;
            for (x = 0; x < w; x++)
            {
                for (y = 0; y < h; y++)
                {
                    heightmap.map[x, y] = bs.ReadDouble();
                }
            }

            bs.Close();
            s.Close();

            tainted++;
        }
开发者ID:BackupTheBerlios,项目名称:ulife-svn,代码行数:24,代码来源:TerrainEngine.cs

示例4: GetEncryptedConnectionString

        internal string GetEncryptedConnectionString()
        {
            #if !USE_CONNECTION_STRING_ENCRYPTION
            // HACK: removing the encrypting
            return CarverLab.Utility.Registry.DefaultProductKey.GetValue("ConnectionString").ToString();
            #else
            //			string sFile = System.Windows.Forms.Application.StartupPath + @"\License.DAT";
            //			System.IO.FileInfo FI = new System.IO.FileInfo(sFile);
            //			System.IO.FileStream FS = FI.Open(System.IO.FileMode.Open, System.IO.FileAccess.Read,System.IO.FileShare.Read);
            string sFile = "";
            System.IO.FileInfo FI = null;
            System.IO.FileStream FS = null;
            try
            {

                try
                {
                    // Check To See if this is a WebApplication
                    if(mvarIsRunningInWebApp)
                    {

                        sFile = @"//" + System.Environment.MachineName.ToString() + @"/License.DAT";
                    }
                    else
                        sFile = System.Windows.Forms.Application.StartupPath + @"\License.Dat";

                    FI = new System.IO.FileInfo(sFile);
                    FS = FI.Open(System.IO.FileMode.Open, System.IO.FileAccess.Read,System.IO.FileShare.Read);
                }
                catch(Exception Err)
                {
                    string sPeek = Err.Message;
                    throw new Exception("Unable to locate a valid License..aborting:" + Err.Message + " " + sFile);
                }

                RijndaelManaged RMCrypto = new RijndaelManaged();

                //byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
                //byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};

                CryptoStream CryptStream = new CryptoStream(FS, RMCrypto.CreateDecryptor(Key,IV), CryptoStreamMode.Read);

                System.IO.StreamReader SR = new System.IO.StreamReader(CryptStream);
                string testread = SR.ReadLine();
                SR.Close();
                CryptStream.Close();
                FS.Close();
                return testread;

            }
            catch(Exception Err)
            {
                throw new Exception(Err.Message);
            }
            #endif
        }
开发者ID:CarverLab,项目名称:Oyster,代码行数:56,代码来源:Oyster.cs

示例5: LoadExcelFileInExcel

        public static void LoadExcelFileInExcel(string excelFileSavePath)
        {
            // SetStatusBar(EStatusBar.eProcessing);
            try
            {
                var filePath = excelFileSavePath;
                // Cursor.Current = Cursors.WaitCursor;
                var fileOkToOpen = true;

                #region check file

                try
                {
                    var newFile = new System.IO.FileInfo(filePath);
                    if (System.IO.File.Exists(filePath))
                    {
                        using (newFile.Open(System.IO.FileMode.Open))
                        {
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                catch (Exception fileExp)
                {
                    fileOkToOpen = false;
                    Console.WriteLine("File already open or other error: " + fileExp.Message);
                }

                #endregion

                if (fileOkToOpen)
                {
                    #region Old öppna med reflect proccess

                    // System.Diagnostics.Process proc = new System.Diagnostics.Process();

                    // string processPath = @"C:\Program Files\Microsoft Office\OFFICE11\";
                    // proc.StartInfo = new System.Diagnostics.ProcessStartInfo(processPath + "Excel" + ".exe", filePath);//C:\\windows\\system32\\
                    #endregion

                    #region Open log in Exel //before: tab window

                    // Start new Excel-instance
                    excelAppOpen = new Application();
                    excelAppOpen.WorkbookDeactivate += ApplicationWorkbookDeactivate;

                    var oldCi = Thread.CurrentThread.CurrentCulture;
                    Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

                    if (excelAppOpen.Workbooks != null)
                    {
                        excelAppOpen.Workbooks._Open(
                            filePath,
                            Type.Missing,
                            0,
                            Type.Missing,
                            XlPlatform.xlWindows,
                            Type.Missing,
                            Type.Missing,
                            Type.Missing,
                            false, // COMMA
                            Type.Missing,
                            Type.Missing,
                            Type.Missing,
                            Type.Missing);
                    }

                    excelAppOpen.Visible = true;

                    Thread.CurrentThread.CurrentCulture = oldCi;

                    #endregion
                }
            }
            catch (Exception fileExp)
            {
                Console.WriteLine(@"Error in LoadComparedLogIn: " + fileExp.Message);
            }
            finally
            {
                // Cursor.Current = Cursors.Default;
            }
        }
开发者ID:perragradeen,项目名称:webbankbudgeter,代码行数:86,代码来源:ExcelOpener.cs

示例6: Download

        public System.Threading.Tasks.Task Download()
        {
            return System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    Status = DownloadStatus.Loading;
                    OnChangedTaskStatus(new EventArgs());
                    var tmpFile = new System.IO.FileInfo(System.IO.Path.GetTempFileName());
                    try
                    {
                        var hashBuilder = new StringBuilder();
                        using (var fileStrm = tmpFile.Open(System.IO.FileMode.Open))
                        using (var imgStrm = ImageInfo.GetStream())
                        {
                            var buff = new byte[1024];
                            var buffLen = 0;
                            while ((buffLen = imgStrm.Read(buff, 0, buff.Length)) > 0)
                                fileStrm.Write(buff, 0, buffLen);

                            fileStrm.Seek(0, System.IO.SeekOrigin.Begin);
                            foreach (var chr in _hashMaker.ComputeHash(fileStrm))
                                hashBuilder.AppendFormat("{0:X2}", chr);
                        }

                        HashText = hashBuilder.ToString();
                        DownloadedTempImageFile = tmpFile;
                        var imgFile = new System.IO.FileInfo(_container.Setting.ImageSaveDirectory.FullName + "\\" + HashText + ".jpg");
                        if (_container.Setting.ImageHashList.Add(HashText) && !imgFile.Exists)
                        {
                            imgFile = tmpFile.CopyTo(imgFile.FullName);
                            Status = DownloadStatus.Loaded;
                            DownloadedImageFile = imgFile;
                            OnChangedTaskStatus(new EventArgs());
                        }
                        else
                        {
                            Status = imgFile.Exists ? DownloadStatus.Loaded : DownloadStatus.Deleted;
                            DownloadedImageFile = imgFile.Exists ? imgFile : null;
                            OnChangedTaskStatus(new EventArgs());
                        }
                    }
                    catch (Exception)
                    {
                        Status = DownloadStatus.Failed;
                        OnChangedTaskStatus(new EventArgs());
                    }
                    finally
                    {
                        if (tmpFile.Exists)
                            tmpFile.Delete();
                    }
                });
        }
开发者ID:namoshika,项目名称:GPlusAutoImageDownloader,代码行数:52,代码来源:ImageDownloader.cs

示例7: EncryptConnectionString

        internal void EncryptConnectionString(string sConnectionString)
        {
            #if !USE_CONNECTION_STRING_ENCRYPTION
            Logger.WriteLog("EncryptConnectionString was skipped.");
            #else
            string sFile = "";
            System.IO.FileInfo FI = null;
            System.IO.FileStream FS = null;
            try
            {

                try
                {
                    // Check To See if this is a WebApplication
                    if(mvarIsRunningInWebApp)
                    {
                        //sFile = @"//localhost/License.DAT";
                        return;
                    }
                    else
                    {
                        sFile = System.Windows.Forms.Application.StartupPath + @"\License.Dat";

                        FI = new System.IO.FileInfo(sFile);
                        FS = FI.Open(System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write,System.IO.FileShare.Write);
                    }
                }
                catch(Exception Err)
                {
                    string sPeek = Err.Message;
                    throw new Exception("Unable to locate a valid License..aborting");
                }
                RijndaelManaged RMCrypto = new RijndaelManaged();
                //byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
                //byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};

                CryptoStream CryptStream = new CryptoStream(FS, RMCrypto.CreateEncryptor(Key,IV), CryptoStreamMode.Write);

                System.IO.StreamWriter SW = new System.IO.StreamWriter(CryptStream);
                SW.WriteLine(sConnectionString);
                SW.Close();
                CryptStream.Close();
                FS.Close();
            }
            catch(Exception Err)
            {
                throw new Exception(Err.Message);
            }
            #endif
        }
开发者ID:CarverLab,项目名称:Oyster,代码行数:50,代码来源:Oyster.cs

示例8: AddObject

		/// <summary>
		/// Add a managed object, passing in the object, the storage tag and the object
		/// name as a string.
		/// </summary>
		/// <param name="name">The name used to identify the object</param>
		/// <param name="obj">The object</param>
		/// <param name="tag">The data storage tab</param>
		public void AddObject(object obj, DataStorageTag tag, string name) {
			BinaryFormatter bf = new BinaryFormatter();
			System.IO.FileInfo serFile = new System.IO.FileInfo(vaultDirectory + "\\" +
				name + extension);
			System.IO.FileStream fs = serFile.Open(System.IO.FileMode.Create, 
				System.IO.FileAccess.Write, System.IO.FileShare.None);

			bf.Serialize(fs, tag);
			bf.Serialize(fs, obj);
			fs.Flush();
			fs.Close();
		}
开发者ID:phoehne,项目名称:Neural.NET,代码行数:19,代码来源:GenericManager.cs

示例9: GetStorageTag

		/// <summary>
		/// Returns the data storage tag for this object.
		/// </summary>
		/// <param name="name">The name of the object</param>
		/// <returns>The data storage tag</returns>
		public DataStorageTag GetStorageTag(string name) {
			System.IO.FileInfo objFile = new System.IO.FileInfo(vaultDirectory + "\\" +
				name + extension);
			System.IO.FileStream fs = objFile.Open(System.IO.FileMode.Open, 
				System.IO.FileAccess.Read, System.IO.FileShare.Read);
			BinaryFormatter bf = new BinaryFormatter();
			object result = bf.Deserialize(fs);
			fs.Close();
			return (DataStorageTag)result;
		}
开发者ID:phoehne,项目名称:Neural.NET,代码行数:15,代码来源:GenericManager.cs

示例10: checkFileOpen

        private bool checkFileOpen()
        {
            System.IO.FileInfo file = new System.IO.FileInfo(this.updateDir.Text);
            System.IO.FileStream stream = null;

            try
            {
                stream = file.Open(System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None);
            }
            catch (Exception)
            {
                return true; //file is open
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
            return false;
        }
开发者ID:BethSundberg,项目名称:JCMS-root,代码行数:22,代码来源:jcmsUpgradeForm.cs

示例11: SerializeHashes

 void SerializeHashes(HashSet<string> imageHashes)
 {
     var hashesPath = new System.IO.FileInfo(string.Format("{0}\\{1}\\imageHashes.xml",
         Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
         System.Reflection.Assembly.GetEntryAssembly().GetName().Name));
     using (var strm = hashesPath.Open(System.IO.FileMode.Create, System.IO.FileAccess.Write))
         _imageHashSerializer.Serialize(strm, imageHashes);
 }
开发者ID:namoshika,项目名称:GPlusAutoImageDownloader,代码行数:8,代码来源:SettingManager.cs

示例12: SerializeCookie

 void SerializeCookie(System.Net.CookieContainer cookies)
 {
     var cookiePath = new System.IO.FileInfo(string.Format("{0}\\{1}\\cookie",
         Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
         System.Reflection.Assembly.GetEntryAssembly().GetName().Name));
     using (var strm = cookiePath.Open(System.IO.FileMode.Create, System.IO.FileAccess.Write))
         _cookieFormatter.Serialize(strm, cookies);
 }
开发者ID:namoshika,项目名称:GPlusAutoImageDownloader,代码行数:8,代码来源:SettingManager.cs

示例13: Main


//.........这里部分代码省略.........
                        outFile.WriteLine ("Time: " + GetTime (now));
                        outFile.WriteLine ("Retv: " + "");
                        outFile.WriteLine ("Errc: " + "");
                        outFile.WriteLine ("Exce: " + GetException (exc));
                    }
                } catch (Exception) {
                } finally {
                    try {
                        exc = null;
                        char[] backSlash = new char[1];
                        backSlash[0] = '\\';
                        outFile.WriteLine ("Name: " + di.FullName.TrimEnd (backSlash));
                        now = System.DateTime.Now;
                        di.Delete ();
                    } catch (Exception e) {
                        exc = e;
                    } finally {
                        outFile.WriteLine ("Func: " + "System.IO.DirectoryInfo.Delete()");
                        outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                        outFile.WriteLine ("Time: " + GetTime (now));
                        outFile.WriteLine ("Retv: " + "");
                        outFile.WriteLine ("Errc: " + "");
                        outFile.WriteLine ("Exce: " + GetException (exc));
                    }
                }
            } catch (Exception) {
            }

            try {
                try {
                    exc = null;
                    sr = null;
                    now = System.DateTime.Now;
                    sr = System.IO.File.OpenText (tempPath + "\\dummyFile6.txt");
                    sr.Close ();
                } catch (Exception e) {
                    exc = e;
                } finally {
                    outFile.WriteLine ("Name: " + tempPath + "\\dummyFile6.txt");
                    outFile.WriteLine ("Func: " + "System.IO.File.OpenText(String)");
                    outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                    outFile.WriteLine ("Time: " + GetTime (now));
                    outFile.WriteLine ("Retv: " + toString (sr));
                    outFile.WriteLine ("Errc: " + "");
                    outFile.WriteLine ("Exce: " + GetException (exc));
                }
                try {
                    exc = null;
                    sw = null;
                    now = System.DateTime.Now;
                    sw = System.IO.File.CreateText (tempPath + "\\dummyFile7.txt");
                    sw.Close ();
                } catch (Exception e) {
                    exc = e;
                } finally {
                    outFile.WriteLine ("Name: " + tempPath + "\\dummyFile7.txt");
                    outFile.WriteLine ("Func: " + "System.IO.File.CreateText(String)");
                    outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                    outFile.WriteLine ("Time: " + GetTime (now));
                    outFile.WriteLine ("Retv: " + toString (sw));
                    outFile.WriteLine ("Errc: " + "");
                    outFile.WriteLine ("Exce: " + GetException (exc));
                }
                try {
                    exc = null;
                    sw = null;
开发者ID:uvbs,项目名称:Holodeck,代码行数:67,代码来源:TestApplication4.cs


注:本文中的System.IO.FileInfo.Open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。