filestream

FileStream disable Close()

你离开我真会死。 提交于 2019-12-12 06:47:19
问题 I'm creating a temporary file with the DeleteOnClose option: var fileStream = File.Create(Path.GetTempFileName(), 4096, FileOptions.DeleteOnClose); Another class(which I cannot modify) will write some data to this file: someObject.WriteDataToFile(fileStream); then I want to retrieve the data for further processing, close the stream, and let the file be automatically deleted. But someObject.WriteDataToFile(fileStream) also calls fileStream.Close() , which will delete the file, so I cannot

How to get an array System.Windows.Media.Color from a BitmapImage?

微笑、不失礼 提交于 2019-12-12 05:54:54
问题 I'm working on a project for edit icons and I need to load an icon. I use the following code for save this icon: var sd = new SaveFileDialog(); sd.ShowDialog(); sd.Filter = "File *.ico|*.ico"; sd.FilterIndex = 0; var path = sd.FileName; if (!sd.CheckPathExists) return; var w = new WriteableBitmap(Dimention, Dimention, 1, 1, PixelFormats.Pbgra32, null); var pix = new int[Dimention,Dimention]; for (int i = 0; i < Dimention; i++) for (int j = 0; j < Dimention; j++) pix[i, j] = ToArgb(IconCanvas

How to Create FileStreame from byte[]?

一曲冷凌霜 提交于 2019-12-12 05:18:16
问题 I have a class like this: class person { public string Name{get;set;} public byte[] PersonImage{get;set;} } When I Load my Person From DataBase I want to show PersonImage in a Image control, so I want to create BitmapImage from my byte[]: var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); var filestream = new MemoryStream(PersonImage); bitmapImage.StreamSource = filestream; bitmapImage.EndInit();// I have Exception in this line My Exception is: No imaging component suitable to

Encrypt to memory stream, pass it to file stream

淺唱寂寞╮ 提交于 2019-12-12 04:56:29
问题 Based on this code: static byte[] EncryptStringToBytes(string plainText, byte[] Key, byte[] IV) { // Check arguments. if (plainText == null || plainText.Length <= 0) throw new ArgumentNullException("plainText"); if (Key == null || Key.Length <= 0) throw new ArgumentNullException("Key"); if (IV == null || IV.Length <= 0) throw new ArgumentNullException("Key"); byte[] encrypted; // Create an Rijndael object // with the specified key and IV. using (Rijndael rijAlg = Rijndael.Create()) { rijAlg

How to write into an existing textfile in windows phone?

末鹿安然 提交于 2019-12-12 03:25:55
问题 If this is the code in opening a textfile "word.txt" in my solution explorer. Stream txtStream = Application.GetResourceStream(new Uri("/sample;component/word.txt", UriKind.Relative)).Stream; using (StreamReader sr = new StreamReader(txtStream)) { string jon; while (!sr.EndOfStream) { jon = sr.ReadLine(); mylistbox.ItemSource = jon; } } How do i write and append in the existing textfile? 回答1: Here is an example public static void WriteBackgroundSetting(string currentBackground) { const string

Should I heed this superficially nonsensical Code Analysis warning? [duplicate]

假如想象 提交于 2019-12-12 03:16:53
问题 This question already has answers here : Why does Code Analysis tell me, “Do not dispose objects multiple times” here: (2 answers) Closed 3 years ago . When I select Analyze > RUn Code Analysis on Solution in Visual Studio 2013, I get, " CA2202 Do not dispose objects multiple times Object 'fs' can be disposed more than once in method 'RoboReporterSQL.SaveReportDataToDB(string, string)'. To avoid generating a System.ObjectDisposedException you should not call Dispose more than one time on an

SQL Filestream Access Denied

时间秒杀一切 提交于 2019-12-12 03:12:25
问题 I'm attempting to implement BLOB Filestream for uploading and downloading files to the SQL database. Problem is I get Access is Denied error when I attempt to wright to the file. I'm using this as the connection string. <add name="connectionname" connectionString="Data Source=lceinforme;Initial Catalog=DEVDB;Persist Security Info=True;User ID=username;Password=password;Max Pool Size=5000" providerName="System.Data.SqlClient" /> From what I've looked up and understand is that I can't use this

Why do I get an UnauthorizedAccessException when downloading data?

丶灬走出姿态 提交于 2019-12-12 02:04:55
问题 I wrote this code to download a file from an FTP server. When the program tries to download and save the file, I get an access denied error. I tried opening the program with admin rights, but it gives the same error. WebClient request = new WebClient(); request.Credentials = new NetworkCredential(txtFTPuser.Text, txtFTPpassword.Text); /*List all directory files*/ byte[] fileData = request.DownloadData(fullDownloaPath);//dnoces.dreamhost.com FileStream fi = File.Create(downloadTo); fi.Write

when a method is called , which thread will be run in c# and java?

可紊 提交于 2019-12-11 22:37:09
问题 Everybody knows we are using multi threading platforms and we are developing multi threading applications. By the way, i couldn't recognize the thread issue. When i call a static method (that is in another class.) , which thread will be run ? does gui thread go the jobs and run method ? i.e: (i am gonna give vb code sample . Logic is the same with java.) Private Sub runValuesTest_Click(sender As System.Object, e As System.EventArgs) Handles RunValuesTest.Click DummyClass.Instance.DoJob() End

How do I stop at a particular point in a file *stream and scan in some values?

笑着哭i 提交于 2019-12-11 17:47:52
问题 I have a file called test.txt the file contains: <this is a test = 1> <more tests = 42 and more "34"> <start>10.213123 41.21231 23.15323</start> <random stuff = "4"> <blah 234> When I see <start> I want to scan in the 3 numbers after into a double like this: x = 10.213123 y = 41.21231 z = 23.15323 I'm sort of confused because here, fgets scans the entire line, how can I scan in the 3 numbers into a double? Because the numbers can be of various lengths? I made this to print out what it reads