filestream

c# email object to stream to attachment

别等时光非礼了梦想. 提交于 2019-12-11 03:31:39
问题 I'm trying to create and send an email attachment from an object which is a list of lists. I found a nicely documented answer here, but still have some confusion. It mentions "get some binary data" //Get some binary data byte[] data = GetData(); I have tested my data by: Console.WriteLine(ieLog.FirstName + "." + ieLog.LastName); I guess my question is how do I turn that into a stream if it isn't already one and then use: //save the data to a memory stream MemoryStream ms = new MemoryStream

How to read from a file using C# code?

旧街凉风 提交于 2019-12-11 03:09:51
问题 I have a file contains two lines . and in which line there is a double parameter . I want to read both lines from the file and save them in an array of doubles . I used the C# code below , but It doesn't work . It doesn't read anything and the array is empty after running the code . Anybody has any idea where did I do wrong ? Thanks for help . private FileStream input; double[] arr; int i = 1; input = new FileStream(Application.StartupPath+"\\City.txt", FileMode.Open, FileAccess.Read);

open pdf from stream using pdfclown in c#

别等时光非礼了梦想. 提交于 2019-12-11 02:34:01
问题 I am really liking pdfclown in c# but I would like to open a pdf from a byte[] array or filestream. I have not found any examples of this for pdfclown. Could anyone help? An example would be something like: using (org.pdfclown.files.File file = new org.pdfclown.bytes.IInputStream(bytes)) { ... } Thanks 回答1: This is the right way to open a file from a byte array: var bytes = . . .; using (var file = new org.pdfclown.files.File(new org.pdfclown.bytes.Buffer(bytes))) { } If you check out PDF

how to set to NULL all the filestream varbinary(max) fields?

谁都会走 提交于 2019-12-11 02:15:23
问题 I need to create a test database out of a huge database where the most data is contained as filestream data. I need to test not filestream related data, so what I'd like to do is to remove the varbinary(max) info. These are the fields I have in my FILE_REPOSITORY_TABLE table: [ID_FILE] [int] NOT NULL, [FILE_DATA] [varbinary](max) FILESTREAM NULL, [GUID] [uniqueidentifier] ROWGUIDCOL NOT NULL What I tried to do is Update FILE_REPOSITORY_TABLE SET FILE = NULL I was expecting this to delete the

FileStream not letting me create file on C drive

霸气de小男生 提交于 2019-12-11 02:12:12
问题 I am using FileStream to create a file with given Length . OpenFileDialog to open a file and FolderBrowserDialog to get the Location. Now the problem is when I choose Location on D:\ or E:\ drive it successfully creates the file. But when I choose C:\ drive it gives an Exception like UnauthorizedAccessException was unhandled. C:\file.mp4 is denied. When I choose desktop as destination it gives no Exception and Does not create the file. I'm using this code private void createFile() { long size

Memory leak using SQL FileStream

♀尐吖头ヾ 提交于 2019-12-11 01:46:49
问题 I have an application that uses a SQL FILESTREAM to store images. I insert a LOT of images (several millions images per days). After a while, the machine stops responding and seem to be out of memory... Looking at the memory usage of the PC, we don't see any process taking a lot of memory (neither SQL or our application). We tried to kill our process and it didn't restore our machine... We then kill the SQL services and it didn't not restore to system. As a last resort, we even killed all

how do disable disk cache in c# invoke win32 CreateFile api with FILE_FLAG_NO_BUFFERING

余生长醉 提交于 2019-12-11 01:33:00
问题 everyone,i have a lot of files write to disk per seconds,i want to disable disk cache to improve performance,i google search find a solution:win32 CreateFile method with FILE_FLAG_NO_BUFFERING and How to empty/flush Windows READ disk cache in C#?. i write a little of code to test whether can worked: const int FILE_FLAG_NO_BUFFERING = unchecked((int)0x20000000); [DllImport("KERNEL32", SetLastError = true, CharSet = CharSet.Auto, BestFitMapping = false)] static extern SafeFileHandle CreateFile(

Performance of FileStream's Write vs WriteByte on an IEnumerable<byte>

一世执手 提交于 2019-12-11 01:28:42
问题 I need to write bytes of an IEnumerable<byte> to a file. I can convert it to an array and use Write(byte[]) method: using (var stream = File.Create(path)) stream.Write(bytes.ToArray()); But since IEnumerable doesn't provide the collection's item count, using ToArray is not recommended unless it's absolutely necessary. So I can just iterate the IEnumerable and use WriteByte(byte) in each iteration: using (var stream = File.Create(path)) foreach (var b in bytes) stream.WriteByte(b); I wonder

Save a file in SQL Server 2008 database with Entity Framework

别等时光非礼了梦想. 提交于 2019-12-10 21:54:16
问题 How can I save a file in SQL Server 2008 database with Entity Framework? I want to use FileStream in SQL Server 2008. 回答1: I don't see why this wouldn't work - filestream columns are just exposed as varbinary(MAX) so you should be able to set the column using Entity Framework: Sample from here: Files newFile = new Files(); newFile.FileID = Guid.NewGuid(); newFile.FileContents = System.IO.File.ReadAllBytes("TextFile1.txt"); ctx.AddObject("Files", newFile); ctx.SaveChanges(); 回答2: Entity

asp.net c# convert filestream to image

帅比萌擦擦* 提交于 2019-12-10 20:47:07
问题 i have a filestream which im trying to convert into a image. i have the following code FileStream imageFile = image["file"] as FileStream; image is a map holding information on the image. please can some one direct me on what I should do next. 回答1: Image.FromStream will take a stream and return an image. Incidentally, if you use Bitmap.FromStream or Image.FromStream , or indeed any of these methods, they all return a Bitmap , so they can all be upcast to Bitmap from Image if you want them to