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; }
public static DateTime GetBuildTimestamp() { string filePath = 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 = BitConverter.ToInt32(b, c_PeHeaderOffset); int secondsSince1970 = BitConverter.ToInt32(b, i + c_LinkerTimestampOffset); DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); dt = dt.AddSeconds(secondsSince1970); dt = dt.ToUniversalTime(); return dt; }
static byte[] readFile(string filename) { //let readFile filename = //// let f = new IO.BufferedStream(new IO.FileStream(filename, IO.FileMode.Open, System.IO.FileAccess.Read)) // let f = new IO.FileStream(filename, IO.FileMode.Open, System.IO.FileAccess.Read) // let fileSize = f.Length |> int // let buf = Array.create(fileSize) 0uy // 符号なし 8 ビット自然数?? http://msdn.microsoft.com/ja-jp/library/dd233193.aspx // let mutable remain = fileSize; // let mutable bufPos = 0; // while remain > 0 do // let readSize = f.Read(buf, bufPos, System.Math.Min(1024, remain)) // bufPos <- bufPos + readSize // remain <- remain - readSize // buf var f = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); var fileSize = (int)f.Length; var buf = new byte[fileSize]; int bufPos = 0; while (fileSize > 0) { int readSize = f.Read(buf, bufPos, System.Math.Min(1024, fileSize)); bufPos += readSize; fileSize -= readSize; } return buf; }
public TorrentFile(string FileName) { try { System.IO.FileStream TorrentFile = new System.IO.FileStream(FileName, System.IO.FileMode.Open); if (TorrentFile.Length == 0) return; byte[] TorrentBytes = new byte[TorrentFile.Length]; TorrentFile.Read(TorrentBytes, 0, TorrentBytes.Length); TorrentFile.Close(); if ((char)TorrentBytes[0] != 'd') { if (OpenError.Length == 0) OpenError = "�����Torrent�ļ�����ͷ��1�ֽڲ���100"; return; } GetTorrentData(TorrentBytes); if (TorrentName.Length == 0 && TorrentFileInfo.Count > 0) TorrentName = TorrentFileInfo[0].Path; } catch (System.Exception ex) { //������־��¼ //H31Debug.PrintLn("TorrentFile:" + ex.StackTrace); } }
private static void OtherWaysToGetReport() { string report = @"d:\bla.rdl"; // string lalal = System.IO.File.ReadAllText(report); // byte[] foo = System.Text.Encoding.UTF8.GetBytes(lalal); // byte[] foo = System.IO.File.ReadAllBytes(report); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { using (System.IO.FileStream file = new System.IO.FileStream(report, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { byte[] bytes = new byte[file.Length]; file.Read(bytes, 0, (int)file.Length); ms.Write(bytes, 0, (int)file.Length); ms.Flush(); ms.Position = 0; } using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("resource")) { using (System.IO.TextReader reader = new System.IO.StreamReader(ms)) { // rv.LocalReport.LoadReportDefinition(reader); } } using (System.IO.TextReader reader = System.IO.File.OpenText(report)) { // rv.LocalReport.LoadReportDefinition(reader); } } }
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; }
/// <summary> /// Компрессия или декомпрессия файла /// </summary> /// <param name="fromFile">Исходный файл для компрессии или декомпрессии</param> /// <param name="toFile">Целевой файл</param> /// <param name="compressionMode">Указывает на компрессию или декомпрессию</param> private static void CompressOrDecompressFile(string fromFile, string toFile, System.IO.Compression.CompressionMode compressionMode) { System.IO.FileStream toFs = null; System.IO.Compression.GZipStream gzStream = null; System.IO.FileStream fromFs = new System.IO.FileStream(fromFile, System.IO.FileMode.Open, System.IO.FileAccess.Read); try { toFs = new System.IO.FileStream(toFile, System.IO.FileMode.Create, System.IO.FileAccess.Write); gzStream = new System.IO.Compression.GZipStream(toFs, compressionMode); byte[] buf = new byte[fromFs.Length]; fromFs.Read(buf, 0, buf.Length); gzStream.Write(buf, 0, buf.Length); } finally { if (gzStream != null) gzStream.Close(); if (toFs != null) toFs.Close(); fromFs.Close(); } }
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; }
//Code PES private string GetBuildNumber() { string strBuildNumber = string.Empty, timestamp = string.Empty; 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 dtDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); dtDate = dtDate.AddSeconds(secondsSince1970); dtDate = dtDate.ToLocalTime(); timestamp = dtDate.ToString("yyyyMMddHHmmss"); if (timestamp == string.Empty) { timestamp = "UNKOWN!"; } strBuildNumber = "Build : " + timestamp; return strBuildNumber; }
private string GetStream(string filePath) { System.IO.FileStream fileStr = new System.IO.FileStream(filePath, System.IO.FileMode.Open); byte[] by = new byte[System.Convert.ToInt32(fileStr.Length)]; fileStr.Read(by, 0, by.Length); fileStr.Close(); return (System.Convert.ToBase64String(by)); }
public static byte[] GetFileBody(String FileName) { using (System.IO.FileStream f = new System.IO.FileStream(FileName, System.IO.FileMode.Open)) { byte[] bytes = new byte[f.Length]; Int32 readbytes = f.Read(bytes, 0, (Int32)f.Length); System.Diagnostics.Debug.Assert(f.Length == readbytes); return bytes; } }
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() ; }
private byte[] GetPictureData(string imagePath) { System.IO.FileStream fs = new System.IO.FileStream(imagePath, System.IO.FileMode.Open); byte[] byteData = new byte[fs.Length]; fs.Read(byteData, 0, byteData.Length); fs.Close(); return byteData; }
protected void Page_Load(object sender, EventArgs e) { try { //文件路径,包括文件名:D:\Products\SRM\C-Procurement\Development\SRM\DataFolder\FileExport\WOItemSearchReport2005041415155.XLS string fullPathName = ""; //文件名:WOItemSearchReport2005041415155.XLS string fileName = ""; if (Page.Request["FilePath"] != null && Page.Request["FilePath"].ToString().Length > 0) { fullPathName = HttpUtility.UrlDecode(Page.Request["FilePath"].ToString()); fileName = HttpUtility.UrlDecode(Page.Request["FileName"].ToString()); } else { Response.Write("<script>window.close();</script>"); return; } //System.IO.FileInfo fleInfo = new System.IO.FileInfo(fullPathName); //Response.Clear(); //Response.ClearHeaders(); //Response.Buffer = true; //Response.AddHeader("content-disposition", "attachment; filename=" + Server.UrlEncode(fileName.Trim())); ////inline(在线打开),attachment(下载) //Response.AddHeader("Content-Length", fleInfo.Length.ToString()); //Response.ContentType = "application/x-msexcel"; //Response.WriteFile(fullPathName); //Response.Flush(); //Response.End(); string fileserverpath = Server.MapPath(fullPathName); System.IO.FileInfo fi = new System.IO.FileInfo(fileserverpath); fi.Attributes = System.IO.FileAttributes.Normal; System.IO.FileStream filestream = new System.IO.FileStream(fileserverpath, System.IO.FileMode.Open); long filesize = filestream.Length; int i = Convert.ToInt32(filesize); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", filesize.ToString()); byte[] fileBuffer = new byte[i]; filestream.Read(fileBuffer, 0, i); filestream.Close(); Response.BinaryWrite(fileBuffer); Response.Flush(); Response.End(); } catch (Exception Ex) { Response.Write("<script>alert('" + Ex.Message.Replace("'", "\\'") + "');window.close();</script>"); Response.End(); } }
public static Signing.LinkedDocument MakeDocument(string documentName, string fqFileName) { LinkedDocument doc = new LinkedDocument(); doc.Document.Name = documentName; using (System.IO.FileStream streamReader = new System.IO.FileStream(fqFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { byte[] pdfBytes = new byte[streamReader.Length]; streamReader.Read(pdfBytes, 0, (int)streamReader.Length); doc.Document.PDFBytes = pdfBytes; } return doc; }
/// <exception cref="System.IO.IOException"></exception> public static void Main3(string[] args) { System.IO.FileStream raf = new System.IO.FileStream("1141067269187.transaction", "r"); long length = raf.Length(); System.Console.Out.WriteLine("File length = " + length); for (int i = 0; i < length; i++) { System.Console.Out.WriteLine(i + ":\t" + raf.Read()); } raf.Close(); }
public TorrentFile(string filename) { System.IO.FileStream TorrentFile = new System.IO.FileStream(filename, System.IO.FileMode.Open); byte[] TorrentBytes = new byte[TorrentFile.Length]; TorrentFile.Read(TorrentBytes, 0, TorrentBytes.Length); TorrentFile.Close(); if ((char)TorrentBytes[0] != 'd') { if (OpenError.Length == 0) OpenError = "Error Torrent files, beginning with the first byte is not 100"; return; } GetTorrentData(TorrentBytes); }
private static DateTime getLinkerTimeStamp(string filePath) { const int PeHeaderOffset = 60; const int LinkerTimestampOffset = 8; byte[] b = new byte[2047]; using (System.IO.Stream s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { s.Read(b, 0, 2047); } int secondsSince1970 = BitConverter.ToInt32(b, BitConverter.ToInt32(b, PeHeaderOffset) + LinkerTimestampOffset); return new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(secondsSince1970); }
private bool Method2(int arg) { if (arg == 0) { int count = 10; } System.IO.FileStream stream = new System.IO.FileStream("Test", System.IO.FileMode.Open); int count_Renamed1 = (int)10f; byte[] buffer = new byte[count_Renamed1]; stream.Read(buffer, 0, buffer.Length); System.Reflection.FieldInfo f = null; return f.IsNotSerialized; }
/// <summary> /// 从文件读取 Stream /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static System.IO.Stream FileToStream(this string fileName) { // 打开文件 var fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); // 读取文件的 byte[] var bytes = new byte[fileStream.Length]; fileStream.Read(bytes, 0, bytes.Length); fileStream.Close(); // 把 byte[] 转换成 Stream var stream = new System.IO.MemoryStream(bytes); return stream; }
private static void Record(long startTime, long stopTime, string name) { System.IO.FileStream fs = new System.IO.FileStream("E:/Config.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite); int r = fs.Read(new byte[102400], 0, 102400); if (r > 0) { fs.WriteByte(13); fs.WriteByte(10); } byte[] buffer = System.Text.Encoding.Default.GetBytes(name + " "+ ", "+ ((float)(stopTime - startTime)) / 10000000); fs.Write(buffer, 0, buffer.Length); fs.Close(); }
static byte[] loadFile(string filename) { // get file System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite); // prepare buffer based on file size byte[] buffer = new byte[(int)fs.Length]; // read file into buffer fs.Read(buffer, 0, buffer.Length); // close file fs.Close(); // return buffer return buffer; }
public int ReadBlock(byte[] Buffer, int Count) { if (HFile == null) { return(0); } try { return(HFile.Read(Buffer, 0, Count)); } catch (System.Exception Excpt) { Err.Add(Excpt); return(0); } return(0); }
public static FileType GetFileType(string filename) { byte[] buffer = new byte[8]{0, 0, 0, 0, 0, 0, 0, 0}; if (System.IO.File.Exists(filename)) { using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) { fs.Read(buffer, 0, buffer.Length); if (buffer.Take(ZipHdr.Length).SequenceEqual(ZipHdr)) return FileType.Zip; else if (buffer.Take(CabHdr.Length).SequenceEqual(CabHdr)) return FileType.Cab; else if (buffer.Take(RarHdr.Length).SequenceEqual(RarHdr)) return FileType.Rar; else if (buffer.Take(GZipHdr.Length).SequenceEqual(GZipHdr)) return FileType.GZip; else if (buffer.Take(OleHdr.Length).SequenceEqual(OleHdr)) { fs.Seek(0, System.IO.SeekOrigin.Begin); return GetOleFileType(fs); } else if (buffer.Take(PstHdr.Length).SequenceEqual(PstHdr)) return FileType.Pst; else if (buffer.Take(PdfHdr.Length).SequenceEqual(PdfHdr)) return FileType.Pdf; else if (buffer.Take(WmfHdr.Length).SequenceEqual(WmfHdr)) return FileType.Wmf; else if (buffer.Take(PngHdr.Length).SequenceEqual(PngHdr)) return FileType.Png; else if (buffer.Take(Tiff1Hdr.Length).SequenceEqual(Tiff1Hdr)) return FileType.Tiff; else if (buffer.Take(Tiff2Hdr.Length).SequenceEqual(Tiff2Hdr)) return FileType.Tiff; else if (buffer.Take(Tiff3Hdr.Length).SequenceEqual(Tiff3Hdr)) return FileType.Tiff; else if (buffer.Take(Tiff4Hdr.Length).SequenceEqual(Tiff4Hdr)) return FileType.Tiff; else if (buffer.Take(ExeDll.Length).SequenceEqual(ExeDll)) return FileType.ExeDll; else if (buffer.Take(Jpeg.Length).SequenceEqual(Jpeg)) return FileType.Jpeg; else if (buffer.Take(Gif.Length).SequenceEqual(Gif)) return FileType.Gif; } } return FileType.Unknown; }
public void Read(int fileOffset, byte[] buffer, int start, int end, out bool ok) { try { fstream.Seek(fileOffset, System.IO.SeekOrigin.Begin); fstream.Read(buffer, start, end - start); ok = true; } catch (Exception e) { System.Console.Error.WriteLine(e); ok = false; } }
public void TestResultsOf1To200() { Numbers n = new Numbers(); n.SendOutputEvent += new Numbers.SendOutputEventHandler(n_SendOutputEvent); n.printNumbers(1, 200); System.IO.FileStream fs = new System.IO.FileStream("C:\\Temp\\knownresults.txt", System.IO.FileMode.Open); byte[] array = new byte[fs.Length]; fs.Read(array, 0, (int)fs.Length); fs.Close(); Assert.IsFalse(System.Text.ASCIIEncoding.ASCII.GetString(array) != _output.ToString()); }
//gets a packet.rv :true success public override bool recv(ref netHeader.NetPacket pkt) { int read_size = 0; bool result = false; try { read_size = htapstream.Read(pkt.buffer, 0, pkt.buffer.Length); result = true; }catch (Exception e) { Console.WriteLine("Packet Recive Error :" + e.ToString()); return(false); } //Console.Error.WriteLine(read_size); if (result) { //original memcmp returns 0 on perfect match //the if statment check if !=0 byte[] eeprombytes = new byte[6]; for (int i = 0; i < 3; i++) { byte[] tmp = BitConverter.GetBytes(DEV9Header.dev9.eeprom[i]); Utils.memcpy(ref eeprombytes, i * 2, tmp, 0, 2); } if ((Utils.memcmp(pkt.buffer, 0, eeprombytes, 0, 6) == false) & (Utils.memcmp(pkt.buffer, 0, broadcast_adddrrrr, 0, 6) == false)) { //ignore strange packets Console.Error.WriteLine("Dropping Strange Packet"); return(false); } if (Utils.memcmp(pkt.buffer, 6, eeprombytes, 0, 6) == true) { //avoid pcap looping packets Console.Error.WriteLine("Dropping Looping Packet"); return(false); } pkt.size = read_size; Console.Error.WriteLine("---------------------Recived Packet"); PacketReader.EthernetFrame ef = new PacketReader.EthernetFrame(pkt); return(true); } else { return(false); } }
/* * public void SaveFileToDatabase(string Path)//обычная таблица с полем варбинари * { * * con.Open(); * com = new SqlCommand(@"INSERT INTO SendFile VALUES (@FileName, @Content)");//(NewId(),@FileName, @Content) * com.Connection = con; * //string Path = @"D:\Desktop\Null.png"; * string FileName = Path.Substring(Path.LastIndexOf('\\') + 1); * byte[] imageData;// массив для хранения бинарных данных файла * using (System.IO.FileStream fs = new System.IO.FileStream(Path, System.IO.FileMode.Open)) * { * imageData = new byte[fs.Length]; * fs.Read(imageData, 0, imageData.Length); * } * * com.Parameters.AddWithValue("@FileName", FileName); * com.Parameters.AddWithValue("@Content", imageData); * * com.ExecuteNonQuery(); * con.Close(); * * } * * * * public void ReadFileFromDatabase(string path) * { * List<File> files = new List<File>(); * * con.Open(); * com = new SqlCommand(@"SELECT * FROM SendFile"); * //com.CommandText = @"SELECT * FROM SendFile"; * com.Connection = con; * * SqlDataReader reader = com.ExecuteReader(); * while (reader.Read()) * { * int id = reader.GetInt32(0); * string filename = reader.GetString(1); * byte[] data = (byte[])reader.GetValue(2); * * File fl = new File(id, filename, data); * files.Add(fl); * } * // сохраним первый файл из списка * if (files.Count > 0) * { * using (System.IO.FileStream fs = new System.IO.FileStream(path +"/"+ files[0].Name, System.IO.FileMode.OpenOrCreate))//@"D:\Desktop\as\" * { * fs.Write(files[0].Content, 0, files[0].Content.Length); * //Console.WriteLine("Изображение '{0}' сохранено", files[0].Name); * } * } * con.Close(); * } * */ public void SaveFileToDatabase(string Path)//таблица файлТейбл { //You need to use the DynamicParameters class and specify the parameter's data type. For the example I created a table TEST with a column called Stream VARBINARY(MAX) /* * using (var connection = new SqlConnection(Properties.Settings.Default.connectionString)) * { * connection.Open(); * using (var fs = File.Open(Properties.Settings.Default.filePath, FileMode.Open)) * { * var sql = "INSERT INTO TEST (Stream) VALUES (@fs)"; * var dParams = new DynamicParameters(); * dParams.Add("@fs", fs, DbType.Binary); * connection.Execute(sql, dParams); * } * } */ con.Open(); com = new SqlCommand(@"INSERT INTO SendFile (file_stream, name) VALUES (@fs,@Nm)");//(NewId(),@FileName, @Content) com.Connection = con; string FileName = Path.Substring(Path.LastIndexOf('\\') + 1); byte[] Content;// массив для хранения бинарных данных файла System.IO.FileStream fs = new System.IO.FileStream(Path, System.IO.FileMode.Open); Content = new byte[fs.Length]; fs.Read(Content, 0, Content.Length); com.Parameters.AddWithValue("@Nm", FileName); com.Parameters.AddWithValue("@fs", Content); int n = 0; bool isSuccess = false;//Решает конфликт имен(если имена совпадают добавляет (n)) while (!isSuccess) { try { com.ExecuteNonQuery(); isSuccess = true; } catch (System.Data.SqlClient.SqlException) { com.Parameters.Clear(); com.Parameters.AddWithValue("@fs", Content); com.Parameters.AddWithValue("@Nm", ("(" + n + ")").ToString() + FileName);//если имена файлов совпадают n++; } } con.Close(); }
private void GenerateReportClaimSku() { int index = 1; string sFileName = System.IO.Path.GetRandomFileName().Substring(0, 8); string sGenName = "ReportClaimSkuNational.csv"; using (System.IO.StreamWriter SW = new System.IO.StreamWriter(Server.MapPath("Upload/" + sFileName + ".csv"))) { SW.WriteLine(String.Format("STORE CLAIMS BY SKU NATIONAL - {0}", DropDownListMonth.SelectedItem.Text)); SW.WriteLine(String.Format("{0}", DropDownListSupplier.SelectedItem.Text)); SW.WriteLine(""); string row = ""; List <StoreRep.Web.Code.Claim> claimSkuSubCategoryList = StoreRep.Web.Code.Claim.GetReportClaimSkuSubCategoryNationalC(Account.GetAccountByUserName(Page.User.Identity.Name.ToString()).AccountId, DropDownListMonth.SelectedItem.Text, Convert.ToInt32(DropDownListSupplier.SelectedValue)); if (claimSkuSubCategoryList.Count > 0) { SW.WriteLine("TOTALS BY LINE ITEMS"); SW.WriteLine(""); SW.WriteLine("LINE ITEM, QUANTITY"); SW.WriteLine(""); foreach (StoreRep.Web.Code.Claim claimSkuSubCategory in claimSkuSubCategoryList) { row = String.Format("{0}, {1}", claimSkuSubCategory.ClaimSkuSubCategory, claimSkuSubCategory.Value); SW.WriteLine(row); index++; } SW.Close(); } else { LabelError.Text = "No rows returned."; PanelError.Visible = true; } } System.IO.FileStream fs = null; fs = System.IO.File.Open(Server.MapPath("Upload/" + sFileName + ".csv"), System.IO.FileMode.Open); byte[] btFile = new byte[fs.Length]; fs.Read(btFile, 0, Convert.ToInt32(fs.Length)); fs.Close(); Response.AddHeader("Content-disposition", "attachment; filename=" + sGenName); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(btFile); Response.End(); }
/// <summary> /// 输出文本文件 /// </summary> /// <param name="path"></param> public static void ResponseFile(string path) { HttpContext.Current.Response.Clear(); System.IO.Stream iStream = null; byte[] buffer = new Byte[10000]; int length; long dataToRead; string filename = System.IO.Path.GetFileName(path); try { iStream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); dataToRead = iStream.Length; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; HttpContext.Current.Response.ContentType = "application/octet-msword"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename= " + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)); HttpContext.Current.Response.AddHeader("Content-Length", dataToRead.ToString()); while (dataToRead > 0) { if (HttpContext.Current.Response.IsClientConnected) { length = iStream.Read(buffer, 0, 10000); HttpContext.Current.Response.OutputStream.Write(buffer, 0, length); HttpContext.Current.Response.Flush(); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { dataToRead = -1; } } } catch (Exception ex) { HttpContext.Current.Response.Write("文件下载时出现错误!" + ex.Message); } finally { if (iStream != null) { iStream.Close(); } } }
/// <summary> /// 将指定的文件输出到客户端,用于客户下载 /// </summary> /// <param name="path">文件相对于站点的路径,以"~/"开头</param> /// <param name="fileName">客户端获取到的用户名</param> /// <param name="context">当前请求的Context对象</param> public static void ResponseFile(string path, string fileName, HttpContext context) { if (context == null) { context = HttpContext.Current; } //将文件的相对路径转化成绝对路径 path = context.Server.MapPath(path); System.IO.Stream iStream = null; byte[] buffer = new Byte[10000]; int length; long dataToRead; try { iStream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); dataToRead = iStream.Length; context.Response.ContentType = "application/octet-stream"; context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); while (dataToRead > 0) { if (context.Response.IsClientConnected) { length = iStream.Read(buffer, 0, 10000); context.Response.OutputStream.Write(buffer, 0, length); context.Response.Flush(); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { dataToRead = -1; } } } catch (Exception ex) { context.Response.Write(ex.Message); } finally { if (iStream != null) { iStream.Close(); } } }
/// <summary> /// 计算一个文件数据的循环冗余效验。使用指定的编码方案。 /// </summary> /// <param name="file">文件。</param> /// <param name="buffLength">允许使用的缓冲区大小。</param> /// <returns></returns> /// <remarks> /// 计算循环冗余效验码时文件长度也在计算之内。 /// </remarks> public byte[] Crc32OfFile(string file, int buffLength) { const int CRCLength = 4;//定义 CRC 长度。 byte[] crc = null; byte[] buff = new byte[CRCLength + buffLength]; int rl; System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); try { while (fs.Position < fs.Length) { rl = fs.Read(buff, CRCLength, buffLength);//从文件读取数据存放到 CRC 空间后。 if (rl > 0) { if (crc == null) { crc = this.Crc32(buff, CRCLength, rl); } else { for (int i = 0; i < CRCLength; i++)//将上次获取的 CRC 复制到 buff 开始位置。 { buff[i] = crc[i]; } crc = this.Crc32(buff, 0, CRCLength + rl); } } } } finally { fs.Close(); } ; System.IO.FileInfo fi = new System.IO.FileInfo(file); long fileLength = fi.Length; if (crc == null) { return(this.Crc32(Thinksea.General.Concat(this.Crc32(new byte[0]), System.Text.Encoding.ASCII.GetBytes(fileLength.ToString())))); } else { return(this.Crc32(Thinksea.General.Concat(crc, System.Text.Encoding.ASCII.GetBytes(fileLength.ToString())))); } }
public static byte[] ReadAllBytes(string path) { if (!IsLongPath(path)) { return(System.IO.File.ReadAllBytes(path)); } var fileHandle = GetFileHandle(GetWin32LongPath(path)); using (var fs = new System.IO.FileStream(fileHandle, System.IO.FileAccess.Read)) { var data = new byte[fs.Length]; fs.Read(data, 0, data.Length); return(data); } }
private string FileRead(string f) { string ret = ""; try { System.IO.FileStream fs = new System.IO.FileStream( f, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] b = new byte[fs.Length]; fs.Read(b, 0, (int)fs.Length); ret = System.Text.Encoding.UTF8.GetString(b); fs.Flush(); fs.Close(); fs.Dispose(); } catch { } return ret; }
public static string ReadAllText(string path, Encoding encoding) { if (!IsLongPath(path)) { return(System.IO.File.ReadAllText(path, encoding)); } var fileHandle = GetFileHandle(GetWin32LongPath(path)); using (var fs = new System.IO.FileStream(fileHandle, System.IO.FileAccess.Read)) { var data = new byte[fs.Length]; fs.Read(data, 0, data.Length); return(encoding.GetString(data)); } }
public static uint CalculateCRC(string fileName) { const int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; uint result = 0xFFFFFFFF; System.IO.FileStream stream = System.IO.File.OpenRead(fileName); int count = stream.Read(buffer, 0, bufferSize); while (count > 0) { for (int i = 0; i < count; i++) { result = ((result) >> 8) ^ tableCRC32[(buffer[i]) ^ ((result) & 0x000000FF)]; } count = stream.Read(buffer, 0, bufferSize); } return(~result); }
public string Read(string fileNameSrc) { Console.WriteLine("读取文件,获取明文:"); string result = string.Empty; using (System.IO.FileStream fsRead = new System.IO.FileStream(fileNameSrc, System.IO.FileMode.Open)) { int fsLen = (int)fsRead.Length; byte[] heByte = new byte[fsLen]; int r = fsRead.Read(heByte, 0, heByte.Length); result = System.Text.Encoding.UTF8.GetString(heByte); } return(result); }
/// <summary> /// Read an entire file into memory. /// </summary> /// <param name="filepath">The path to the file to read.</param> /// <returns>The binary array from the file.</returns> private byte[] ReadEntireFile(string filepath) { System.IO.FileInfo file = new System.IO.FileInfo(filepath); System.IO.FileStream stream = file.OpenRead(); byte[] buffer = new byte[10240]; List <byte> filebody = new List <byte>(); int size = stream.Read(buffer, 0, 10240); int totalsize = 0; while (size > 0) { for (int i = 0; i < size; i++) { filebody.Add(buffer[i]); totalsize++; } size = stream.Read(buffer, 0, 10240); } stream.Close(); return(filebody.ToArray()); }
/// <summary> /// Loads a CTAGS output file to be parsed by the filter. Will have /// been already generated by CTAGS. /// (Recommended: <a href="https://github.com/universal-ctags/ctags">https://github.com/universal-ctags/ctags</a>) /// Only one file can be loaded at once. /// </summary> /// <param name="file">Path to the CTAGS output file.</param> public void LoadFromCtagsFile(string file) { System.IO.FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Open); int length = (int)fs.Length; byte[] buff = new byte[length]; fs.Seek(0, System.IO.SeekOrigin.Begin); fs.Read(buff, 0, length); fs.Close(); string fileContents = Encoding.UTF8.GetString(buff); LoadFromCtagsString(fileContents); }
/// <summary> /// Convert local image to binary array /// </summary> /// <param name="imagePath"></param> /// <returns></returns> public static byte[] ImageToBinary(string imagePath) { byte[] b = new byte[] { }; try { System.IO.FileStream fS = new System.IO.FileStream(imagePath, System.IO.FileMode.Open, System.IO.FileAccess.Read); b = new byte[fS.Length]; fS.Read(b, 0, (int)fS.Length); fS.Close(); } catch (Exception ex) { } return(b); }
private static void AddFile(NZlib.Zip.ZipOutputStream zipOutputStream, File file) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(file.Path); System.IO.FileStream fileStream = System.IO.File.OpenRead(fileInfo.FullName); System.DateTime dateTime = fileInfo.LastWriteTime; long filesize = fileInfo.Length; byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); fileStream.Close(); Add(zipOutputStream, file.Name, dateTime, filesize, buffer); }
/// <summary> /// 返回照片元数据 /// </summary> /// <param name="imagePath"></param> /// <param name="buffer"></param> public void ImageBuffer(string imagePath, ref byte[] buffer) { try { System.IO.FileStream stream = new System.IO.FileStream(imagePath, System.IO.FileMode.Open, System.IO.FileAccess.Read); buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); stream.Close(); } catch (Exception ex) { throw new ApplicationException("读取图像错误: " + ex.Message); } }
private string GetMacByFile() { try { using var f = new System.IO.FileStream("/sys/class/net/wlan0/address", System.IO.FileMode.Open); var bytes = new byte[f.Length]; f.Read(bytes); return(System.Text.Encoding.UTF8.GetString(bytes)); } catch (System.Exception) { return(string.Empty); } }
public bool Read() { if (!_readStart) { _stream = new System.IO.FileStream(this.FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite); _code = GetType(this.FilePath); _currentPosition = 0; _fileLength = _stream.Length; _readStart = true; } if (_currentPosition < _fileLength) { _readEnd = false; byte[] readBuffer = new byte[this.ReadBytes]; _stream.Seek(_currentPosition, System.IO.SeekOrigin.Begin); int currentReadBytes = _stream.Read(readBuffer, 0, readBuffer.Length); _currentPosition += currentReadBytes; if (currentReadBytes < _readBytes) { byte[] temp = new byte[currentReadBytes]; int index = 0; while (index < currentReadBytes) { temp[index] = readBuffer[index]; index++; } readBuffer = temp; } _readStr = _code.GetString(readBuffer); if (_currentPosition < _fileLength) { int offsetStrPosition = GetPosition(_readStr, this.OffsetStrArray); if (offsetStrPosition > 0) { string removeStr = _readStr.Substring(offsetStrPosition + 1); _readStr = _readStr.Remove(offsetStrPosition + 1); _currentPosition = _currentPosition - _code.GetBytes(removeStr).Length; } } } else { _readEnd = true; _stream.Dispose(); } return(!_readEnd); }
/// <summary> /// Кодирует обьект в заданой кодировке. /// </summary> /// <param name="a">Название кодировки.</param> public void changingthecoding(string a) { Encoding e; for (int i = 0; i < fileList.Count; i++) { System.IO.FileStream stream = fileStream(fileList[i]); switch (a.ToLower()) { case "unicode": e = Encoding.Unicode; break; case "ascii": e = Encoding.ASCII; break; case "default": e = Encoding.Default; break; case "utf32": e = Encoding.UTF32; break; case "utf7": e = Encoding.UTF7; break; case "utf8": e = Encoding.UTF8; break; default: throw new Exception(string.Format("Данная кодировка отсутствует.")); } byte[] buffer = new byte[4096]; byte[] newBuffer = new byte[4096]; while (stream.Position < stream.Length) { int count = stream.Read(buffer, 0, buffer.Length); for (int j = 0; j < count - 1; j++) { newBuffer = e.GetBytes(buffer[j] + " "); } stream.Write(newBuffer, 0, newBuffer.Length); stream.Flush(); } if (Messang != null) { Messang(this, new MyEvenArgs(string.Format("Объект '{0}' был изменен", fileList[i]))); } stream.Close(); } }
//static bool isfirst = false; // buf must be at least 12 bytes. //--F-------------ADDCOOK------------------ public void CopyInto(List <LongIntComboListPart.B12> cbuffer, byte[] buf) { ensurefzblock(false, blockbuflen); try { int flen = (int)fzblock.Length; int b12count = flen / 12; cbuffer.Clear(); int newcap = b12count; /*if (isfirst) * { * isfirst = false; * newcap *= 2; * }*/ if (newcap > cbuffer.Capacity) { cbuffer.Capacity = newcap; } // Read from existing unsorted zblock file into buffer. fzblock.Seek(0, System.IO.SeekOrigin.Begin); LongIntComboListPart.B12 b12; b12.A = 0; b12.B = 0; for (int i = 0; i != b12count; i++) { int szr = fzblock.Read(buf, 0, 12); #if DEBUG if (12 != szr) { throw new Exception("Unable to read"); } #endif b12.SetFromArray(buf); cbuffer.Add(b12); } } catch (Exception e) { cbuffer.Clear(); XLog.errorlog("LongIntComboList CopyInto failure; zblock skipped: " + e.ToString()); } _justclose(); }
//<Snippet1> public void EncodeWithString() { System.IO.FileStream inFile; byte[] binaryData; try { inFile = new System.IO.FileStream(inputFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); binaryData = new Byte[inFile.Length]; long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length); inFile.Close(); } catch (System.Exception exp) { // Error creating stream or reading from it. System.Console.WriteLine("{0}", exp.Message); return; } // Convert the binary input into Base64 UUEncoded output. string base64String; try { base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length); } catch (System.ArgumentNullException) { System.Console.WriteLine("Binary data array is null."); return; } // Write the UUEncoded version to the output file. System.IO.StreamWriter outFile; try { outFile = new System.IO.StreamWriter(outputFileName, false, System.Text.Encoding.ASCII); outFile.Write(base64String); outFile.Close(); } catch (System.Exception exp) { // Error creating stream or writing to it. System.Console.WriteLine("{0}", exp.Message); } }
//</Snippet1> // Note: This works, but should come up with something a // little more useful. //<Snippet2> private void CreateServerDocumentFromByteArray(string documentPath) { int runtimeVersion = 0; ServerDocument serverDocument1 = null; System.IO.FileStream stream = null; try { runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath); if (runtimeVersion == 3) { // Read the file into a byte array. stream = new System.IO.FileStream( documentPath, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] buffer = new byte[(int)stream.Length]; stream.Read(buffer, 0, (int)buffer.Length); // Display the number of bytes in the document. serverDocument1 = new ServerDocument(buffer, "*.xlsx"); MessageBox.Show("The Document property contains " + serverDocument1.Document.Length.ToString() + " bytes."); } } catch (System.IO.FileNotFoundException) { System.Windows.Forms.MessageBox.Show("The specified document does not exist."); } catch (UnknownCustomizationFileException) { System.Windows.Forms.MessageBox.Show("The specified document has a file " + "extension that is not supported by Visual Studio Tools for Office."); } finally { if (serverDocument1 != null) { serverDocument1.Close(); } if (stream != null) { stream.Close(); } } }
byte[] GetFile(string s) { System.IO.FileStream fs = System.IO.File.OpenRead(s); byte[] data = new byte[fs.Length]; int br = fs.Read(data, 0, data.Length); if (br != fs.Length) { throw new System.IO.IOException(s); } fs.Close(); var uri = new Uri(s, UriKind.Absolute); System.IO.File.Delete(uri.LocalPath); return(data); }
private void queryBufferButton_Click(object sender, EventArgs e) { try { System.IO.FileStream stream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); Byte[] imgData = new byte[stream.Length]; stream.Read(imgData, 0, imgData.Length); stream.Close(); AppendFileInfo(ImageX.QueryBuffer(imagXpress1, imgData, 1)); } catch (Accusoft.ImagXpressSdk.ImagXpressException ex) { MessageBox.Show(ex.Message); } }
public int Read(byte[] abData, int nDataSize) { if (m_theFile == null) { return(0); } try { return(m_theFile.Read(abData, 0, nDataSize)); } catch (System.IO.IOException) { return(0); } }
public static void loadbiosflashfile(string name) //load flash ram file { try { System.IO.FileInfo fi = new System.IO.FileInfo(name); System.IO.FileStream fs = fi.OpenRead(); fs.Read(bios_flash, 0, 256 * kb); fs.Close(); dc.dcon.WriteLine("Flash ram readed from \"" + name + "\""); } catch //well the file does not exist so... create it :) { dc.dcon.WriteLine("Flash ram \"" + name + "\" not found. Creating one"); savebiosflashfile(name); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static void readFileToBytes(android.content.res.AssetFileDescriptor fd, byte[] data) throws java.io.IOException private static void readFileToBytes(AssetFileDescriptor fd, sbyte[] data) { System.IO.FileStream inputStream = fd.createInputStream(); int bytesRead = 0; while (bytesRead < data.Length) { int res = inputStream.Read(data, bytesRead, (data.Length - bytesRead)); if (res == -1) { break; } bytesRead += res; } }
public void TestUplaod(string filepath) { var api = this.BaseStorageUrl + "UploadFileMobile"; var fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open); //获取文件大小 long size = fs.Length; byte[] bs = new byte[size]; //将文件读到byte数组中 fs.Read(bs, 0, bs.Length); fs.Close(); var response = HttpHelper.PostFile(api, bs, System.IO.Path.GetFileName(filepath)); Console.WriteLine(response); Console.ReadLine(); }
static string EncodeFromFile(string path) { var base64 = ""; using (var fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read)) using (var ms = new System.IO.MemoryStream()) { var buf = new byte[1024]; var len = 0; do { len = fs.Read(buf, 0, buf.Length); ms.Write(buf, 0, len); } while (len > 0); base64 = Convert.ToBase64String(ms.ToArray()); } return base64; }
public static string ToBase64String(string imagePath) { string inFileName = imagePath; System.IO.FileStream inFile; byte[] bs; inFile = new System.IO.FileStream(inFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); bs = new byte[inFile.Length]; int readBytes = inFile.Read(bs, 0, (int)inFile.Length); inFile.Close(); string base64String; base64String = System.Convert.ToBase64String(bs); return base64String; }
public static void CompressFile(string sourceFile, string destinationFile) { int checkCounter; if (System.IO.File.Exists(sourceFile) == false) { return; } byte[] buffer; System.IO.FileStream sourceStream = null; System.IO.FileStream destinationStream = null; //System.IO.Compression.DeflateStream compressedStream = null; System.IO.Compression.GZipStream compressedStream = null; try { sourceStream = new System.IO.FileStream(sourceFile, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read); buffer = new byte[Convert.ToInt64(sourceStream.Length)]; checkCounter = sourceStream.Read(buffer, 0, buffer.Length); //output (ZIP) file name destinationStream = new System.IO.FileStream(destinationFile, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write); // Create a compression stream pointing to the destiantion stream compressedStream = new System.IO.Compression.GZipStream(destinationStream, System.IO.Compression.CompressionMode.Compress, true); compressedStream.Write(buffer, 0, buffer.Length); } finally { // Make sure we allways close all streams if (sourceStream != null) { sourceStream.Close(); } if (compressedStream != null) { compressedStream.Close(); } if (destinationStream != null) { destinationStream.Close(); } } }
public static byte[] ReadBytes(string filename) { byte[] bytes; using(System.IO.FileStream fileStream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { int length = (int)fileStream.Length; // get file length bytes = new byte[length]; // create buffer int count; // actual number of bytes read int sum = 0; // total number of bytes read // read until Read method returns 0 (end of the stream has been reached) while ((count = fileStream.Read(bytes, sum, length - sum)) > 0) { sum += count; // sum is a buffer offset for next reading } } return bytes; }
public SceneTableEntryMajora(ROMHandler rom, string fn) { ROM = rom; inROM = false; Offset = -1; IsOffsetRelative = false; sceneStartAddress = sceneEndAddress = 0; Unknown1 = Unknown2 = Unknown3 = Unknown4 = 0; System.IO.FileStream fs = new System.IO.FileStream(fn, System.IO.FileMode.Open); data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); fs.Close(); Name = System.IO.Path.GetFileNameWithoutExtension(fn); }
// http://www.codinghorror.com/blog/2005/04/determining-build-date-the-hard-way.html private static DateTime RetrieveLinkerTimestamp(string filePath) { const int peHeaderOffset = 60; const int linkerTimestampOffset = 8; byte[] b = new byte[2048]; System.IO.FileStream 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(); } DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(BitConverter.ToInt32(b, BitConverter.ToInt32(b, peHeaderOffset) + linkerTimestampOffset)); return dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours); }