本文整理汇总了C#中System.IO.FileStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileStream.Close方法的具体用法?C# System.IO.FileStream.Close怎么用?C# System.IO.FileStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了System.IO.FileStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public void Save()
{
System.IO.FileStream stream = new System.IO.FileStream(this.fileName, System.IO.FileMode.Create);
XmlSerializer serializer = new XmlSerializer(typeof(CryptoPasswordProperties));
serializer.Serialize(stream, this);
stream.Close();
}
示例2: BackupCompradoresLinkButton_Click
protected void BackupCompradoresLinkButton_Click(object sender, EventArgs e)
{
if (CedWebRN.Fun.NoEstaLogueadoUnUsuarioPremium((CedWebEntidades.Sesion)Session["Sesion"]))
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Esta funcionalidad es exclusiva del SERVICIO PREMIUM. Contáctese con Cedeira Software Factory para acceder al servicio.');</script>");
}
else
{
List<CedWebEntidades.Comprador> compradores = CedWebRN.Comprador.Lista(((CedWebEntidades.Sesion)Session["Sesion"]).Cuenta, (CedEntidades.Sesion)Session["Sesion"], false);
if (compradores.Count == 0)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('No hay datos de Compradores para descargar.');</script>");
}
else
{
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(compradores.GetType());
System.IO.MemoryStream m = new System.IO.MemoryStream();
System.Xml.XmlWriter writerdememoria = new System.Xml.XmlTextWriter(m, System.Text.Encoding.GetEncoding("ISO-8859-1"));
x.Serialize(writerdememoria, compradores);
m.Seek(0, System.IO.SeekOrigin.Begin);
string nombreArchivo = "eFact-Compradores-" + ((CedWebEntidades.Sesion)Session["Sesion"]).Cuenta.Id.Replace(".", String.Empty).ToUpper() + ".xml";
System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath(@"~/Temp/" + nombreArchivo), System.IO.FileMode.Create);
m.WriteTo(fs);
fs.Close();
Server.Transfer("~/DescargaTemporarios.aspx?archivo=" + nombreArchivo, false);
}
}
}
示例3: SaveAssembly
public static void SaveAssembly(string assemblyName, string destinationPath)
{
string sql = @"SELECT af.name, af.content FROM sys.assemblies a INNER JOIN sys.assembly_files af ON a.assembly_id = af.assembly_id WHERE a.name = @assemblyname";
using (SqlConnection conn = new SqlConnection("context connection=true")) //Create current context connection
{
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
SqlParameter param = new SqlParameter("@assemblyname", System.Data.SqlDbType.NVarChar);
param.Value = assemblyName;
// param.Size = 128;
cmd.Parameters.Add(param);
cmd.Connection.Open(); //Open the context connetion
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read()) //Iterate through assembly files
{
string assemblyFileName = reader.GetString(0); //get assembly file name from the name (first) column
System.Data.SqlTypes.SqlBytes bytes = reader.GetSqlBytes(1); //get assembly binary data from the content (second) column
string outputFile = System.IO.Path.Combine(destinationPath, assemblyFileName);
SqlContext.Pipe.Send(string.Format("Exporting assembly file [{0}] to [{1}]", assemblyFileName, outputFile)); //Send information about exported file back to the calling session
using (System.IO.FileStream byteStream = new System.IO.FileStream(outputFile, System.IO.FileMode.CreateNew))
{
byteStream.Write(bytes.Value, 0, (int)bytes.Length);
byteStream.Close();
}
}
}
}
conn.Close();
}
}
示例4: button1_Click
private void button1_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItem!=null)
{
SaveFileDialog sav=new SaveFileDialog();
sav.Filter = "*.hex|*.hex|*.*|*'.*";
DialogResult res = sav.ShowDialog();
if (res==DialogResult.OK)
{
try
{
byte[] blk = myConn.PLCGetBlockInMC7(listBox1.SelectedItem.ToString());
System.IO.FileStream _FileStream = new System.IO.FileStream(sav.FileName,
System.IO.FileMode.Create,
System.IO.FileAccess.Write);
_FileStream.Write(blk, 0, blk.Length);
_FileStream.Close();
MessageBox.Show("Block " + listBox1.SelectedItem.ToString() + " saved to: " + sav.FileName);
}
catch(Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
}
示例5: BackupVendedorLinkButton_Click
protected void BackupVendedorLinkButton_Click(object sender, EventArgs e)
{
try
{
if (CedWebRN.Fun.NoEstaLogueadoUnUsuarioPremium((CedWebEntidades.Sesion)Session["Sesion"]))
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Esta funcionalidad es exclusiva del SERVICIO PREMIUM. Contáctese con Cedeira Software Factory para acceder al servicio.');</script>");
}
else
{
CedWebEntidades.Vendedor vendedor = new CedWebEntidades.Vendedor();
vendedor.IdCuenta = ((CedWebEntidades.Sesion)Session["Sesion"]).Cuenta.Id;
CedWebRN.Vendedor.Leer(vendedor, (CedEntidades.Sesion)Session["Sesion"]);
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(vendedor.GetType());
System.IO.MemoryStream m = new System.IO.MemoryStream();
System.Xml.XmlWriter writerdememoria = new System.Xml.XmlTextWriter(m, System.Text.Encoding.GetEncoding("ISO-8859-1"));
x.Serialize(writerdememoria, vendedor);
m.Seek(0, System.IO.SeekOrigin.Begin);
string nombreArchivo = "eFact-Vendedor-" + ((CedWebEntidades.Sesion)Session["Sesion"]).Cuenta.Id.Replace(".", String.Empty).ToUpper() + ".xml";
System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath(@"~/Temp/" + nombreArchivo), System.IO.FileMode.Create);
m.WriteTo(fs);
fs.Close();
Server.Transfer("~/DescargaTemporarios.aspx?archivo=" + nombreArchivo, false);
}
}
catch (Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.ElementoInexistente)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('No hay datos del Vendedor para descargar.');</script>");
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString() + "');</script>");
}
}
示例6: GetMD5
public static string GetMD5(string filePath)
{
string strResult = "";
string strHashData = "";
byte[] arrbytHashValue;
System.IO.FileStream oFileStream = null;
System.Security.Cryptography.MD5CryptoServiceProvider oMD5Hasher =
new System.Security.Cryptography.MD5CryptoServiceProvider();
try
{
oFileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream);//计算指定Stream 对象的哈希值
oFileStream.Close();
//由以连字符分隔的十六进制对构成的String,其中每一对表示value 中对应的元素;例如“F-2C-4A”
strHashData = System.BitConverter.ToString(arrbytHashValue);
//替换-
strHashData = strHashData.Replace("-", "");
strResult = strHashData;
}
catch (System.Exception ex)
{
}
return strResult;
}
示例7: LoadImage
public static BitmapImage LoadImage(string path)
{
try
{
var fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
fs.Seek(0, System.IO.SeekOrigin.Begin);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
var ms = new System.IO.MemoryStream(bytes);
ms.Position = 0;
var image = new BitmapImage();
image.BeginInit();
image.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
image.CacheOption = BitmapCacheOption.OnLoad;
image.StreamSource = ms;
image.EndInit();
return image;
}
catch (Exception ex)
{
}
return null;
}
示例8: GetBulidTime
public static DateTime GetBulidTime()
{
var filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
const int cPeHeaderOffset = 60;
const int cLinkerTimestampOffset = 8;
var b = new byte[2048];
System.IO.Stream s = null;
try
{
s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
s.Read(b, 0, 2048);
}
finally
{
if (s != null)
{
s.Close();
}
}
var i = BitConverter.ToInt32(b, cPeHeaderOffset);
var secondsSince1970 = BitConverter.ToInt32(b, i + cLinkerTimestampOffset);
var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
dt = dt.AddSeconds(secondsSince1970);
dt = dt.ToLocalTime();
return dt;
}
示例9: ByteArrayToFile
public static bool ByteArrayToFile(string fileName, byte[] data)
{
try
{
// Open file for reading
System.IO.FileStream _FileStream =
new System.IO.FileStream(fileName, System.IO.FileMode.Create,
System.IO.FileAccess.Write);
// Writes a block of bytes to this stream using data from
// a byte array.
_FileStream.Write(data, 0, data.Length);
// close file stream
_FileStream.Close();
return true;
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}",
_Exception.ToString());
}
// error occured, return false
return false;
}
示例10: Load
public void Load()
{
System.IO.FileStream file = new System.IO.FileStream("data.dat",System.IO.FileMode.Open ) ;
Byte[] buffer1 = System.BitConverter.GetBytes( Existe[0] ) ;
Byte[] buffer2 = System.BitConverter.GetBytes( Left[0] ) ;
Byte[] buffer3 = System.BitConverter.GetBytes( Top[0] ) ;
Byte[] buffer4 = System.BitConverter.GetBytes( Color[0].ToArgb() ) ;
Byte[] buffer5 = System.Text.Encoding.BigEndianUnicode.GetBytes( Text[0], 0 , Text[0].Length ) ;
Byte[] bufferM1 = System.BitConverter.GetBytes( MainLeft ) ;
Byte[] bufferM2 = System.BitConverter.GetBytes( MainTop ) ;
file.Read( bufferM1, 0, bufferM1.Length ) ;
MainLeft = System.BitConverter.ToInt32( bufferM1 , 0 ) ;
file.Read( bufferM2, 0, bufferM2.Length ) ;
MainTop = System.BitConverter.ToInt32( bufferM2 , 0 ) ;
for ( int i = 0 ; i < MAX_POSTS ; i++ )
{
file.Read( buffer1, 0, buffer1.Length ) ;
Existe[i] = System.BitConverter.ToBoolean( buffer1 , 0 ) ;
file.Read( buffer2, 0, buffer2.Length ) ;
Left[i] = System.BitConverter.ToInt32( buffer2 , 0 ) ;
file.Read( buffer3, 0, buffer3.Length ) ;
Top[i] = System.BitConverter.ToInt32( buffer3 , 0 ) ;
file.Read( buffer4, 0, buffer4.Length ) ;
Color[i] = System.Drawing.Color.FromArgb( System.BitConverter.ToInt32(buffer4, 0 ) ) ;
file.Read( buffer5, 0, buffer5.Length ) ;
Text[i] = System.Text.Encoding.BigEndianUnicode.GetChars( buffer5 ) ;
}
file.Close() ;
}
示例11: FileToByteArray
public byte[] FileToByteArray(string _FileName)
{
byte[] _Buffer = null;
try
{
// Open file for reading
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
// attach filestream to binary reader
System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
// get total byte length of the file
long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
// read entire file into buffer
_Buffer = _BinaryReader.ReadBytes((Int32)(_TotalBytes));
// close file reader
_FileStream.Close();
_FileStream.Dispose();
_BinaryReader.Close();
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
}
return _Buffer;
}
示例12: loadToolStripMenuItem_Click
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
SkeletDrawInfo _sdi;
System.IO.Stream stream = new System.IO.FileStream(ofd.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
try
{
_sdi = (SkeletDrawInfo)formatter.Deserialize(stream);
if (_sdi.nodes.Length == skelet.bones.Length && _sdi.relations.Length == sdi.relations.Length)
{
_sdi.sk = skelet;
for (int o = 0; o < _sdi.nodes.Length; o++)
_sdi.nodes[o].bone = skelet.bones[_sdi.nodes[o].index];
sdi = _sdi;
Invalidate();
}
}
catch (System.Runtime.Serialization.SerializationException)
{
System.Windows.Forms.MessageBox.Show("Wrong file format");
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
finally
{
stream.Close();
}
}
}
示例13: Execute
public static int Execute( List<string> args )
{
if ( args.Count < 2 ) {
Console.WriteLine( "Usage: ByteHotfix [filename] [location-byte] [location-byte] etc." );
Console.WriteLine( "example: ByteHotfix 325.new 3A9A3-94 3AA72-A4 3AA73-32 3AB53-51" );
return -1;
}
/*
args = new string[] { @"c:\#gn_chat\scenario.dat.ext.ex\325.new" ,
"3A9A3-94", "3AA72-A4", "3AA73-32", "3AB53-51" };
*/
try {
string inFilename = args[0];
using ( var fi = new System.IO.FileStream( inFilename, System.IO.FileMode.Open ) ) {
for ( int i = 1; i < args.Count; i++ ) {
String[] v = args[i].Split( new char[] { '-' } );
int location = int.Parse( v[0], NumberStyles.AllowHexSpecifier );
byte value = byte.Parse( v[1], NumberStyles.AllowHexSpecifier );
fi.Position = location;
fi.WriteByte( value );
}
fi.Close();
}
return 0;
} catch ( Exception ex ) {
Console.WriteLine( "Exception: " + ex.Message );
return -1;
}
}
示例14: RetrieveLinkerTimestamp
private DateTime RetrieveLinkerTimestamp()
{
string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
const int c_PeHeaderOffset = 60;
const int c_LinkerTimestampOffset = 8;
byte[] b = new byte[2048];
System.IO.Stream s = null;
try
{
s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
s.Read(b, 0, 2048);
}
finally
{
if (s != null)
{
s.Close();
}
}
int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
dt = dt.AddSeconds(secondsSince1970);
dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
return dt;
}
示例15: DownloadFile
//下载网络文件
/// <summary>
/// 下载网络文件 带进度条
/// </summary>
/// <param name="URL"></param>
/// <param name="fileName"></param>
/// <param name="progressBar1"></param>
/// <returns></returns>
public static bool DownloadFile(string URL, string fileName,ProgressBar progressBar1)
{
try
{
System.Net.HttpWebRequest httpWebRequest1 = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
System.Net.HttpWebResponse httpWebResponse1 = (System.Net.HttpWebResponse)httpWebRequest1.GetResponse();
long totalLength = httpWebResponse1.ContentLength;
progressBar1.Maximum = (int)totalLength;
System.IO.Stream stream1 = httpWebResponse1.GetResponseStream();
System.IO.Stream stream2 = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
long currentLength = 0;
byte[] by = new byte[1024];
int osize = stream1.Read(by, 0, (int)by.Length);
while (osize > 0)
{
currentLength = osize + currentLength;
stream2.Write(by, 0, osize);
progressBar1.Value = (int)currentLength;
osize = stream1.Read(by, 0, (int)by.Length);
}
stream2.Close();
stream1.Close();
return (currentLength == totalLength);
}
catch
{
return false;
}
}