filestream

write, update and save a well-formed xml file in as3

早过忘川 提交于 2020-01-06 02:44:13
问题 I am trying to update an xml file and save elements inside of an already saved root element. I have only found examples where the xml files are just opened and not saved. Can someone help me to find the best way to save the results? My project right now looks like this: I am loading an xml file via URLLoader/URLRequest and display the contents in several text fields. New text from an input field is saved (appended) via FileStream directly to the xml file in the applicationStorageDirectory

Cant write files do server with Filestream class (Return 400 - Bad Request)

我是研究僧i 提交于 2020-01-03 04:51:46
问题 When i try to write a image file to server, using this little code: [HttpPost] public IActionResult Post([FromBody] ImgViewModel imagem) { try { if (imagem.base64.Contains(",")) { imagem.base64 = imagem.base64 .Substring(imagem.base64 .IndexOf(",") + 1); } imagem.FileAsByteArray = Convert.FromBase64String(imagem.base64); var folderName = Path.Combine("Resources", "Images"); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); var ext = Path.GetExtension(imagem.filename)

Writing bytes from a struct into a file with c#

风流意气都作罢 提交于 2020-01-03 03:24:25
问题 Good morning everyone! I'm with a new problem here. I have to write down a data that comes from a struct that I declared in my sistem. The struct I created has only two fields and I use to to later conevrt it into bytes. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] public struct MyStructData { public short Id; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] public string Name; } I convert this struct in bytes with the following code: private byte[] getBytes

Pass Base64 encoded string using JsonTextReader value as new stream

风格不统一 提交于 2020-01-03 02:59:25
问题 We are consuming large JSON streams from an HTTP Post request. The goal is to stream the incoming body as JSON using JsonTextReader and extract the embedded base64 encoded binary files to disk. In XML, an equivalent method might be XMLReader.ReadElementContentAsBase64Async. Using JSON.NET, as we iterative how do we send the each item of the encodedImages array into a FileStream without holding the whole string in memory. Example JSON Object: { "company":"{clientCompany}", "batchName":"

How to Lock a file and avoid readings while it's writing

假如想象 提交于 2020-01-01 08:59:47
问题 My web application returns a file from the filesystem. These files are dynamic, so I have no way to know the names o how many of them will there be. When this file doesn't exist, the application creates it from the database. I want to avoid that two different threads recreate the same file at the same time, or that a thread try to return the file while other thread is creating it. Also, I don't want to get a lock over a element that is common for all the files. Therefore I should lock the

How to Lock a file and avoid readings while it's writing

若如初见. 提交于 2020-01-01 08:59:21
问题 My web application returns a file from the filesystem. These files are dynamic, so I have no way to know the names o how many of them will there be. When this file doesn't exist, the application creates it from the database. I want to avoid that two different threads recreate the same file at the same time, or that a thread try to return the file while other thread is creating it. Also, I don't want to get a lock over a element that is common for all the files. Therefore I should lock the

How can I remove the oldest lines in a file when using a FileStream and StreamWriter?

梦想与她 提交于 2019-12-31 07:31:41
问题 Based on Prakash's answer here, I thought I'd try something like this to remove the oldest lines in a file prior to adding a new line to it: private ExceptionLoggingService() { _fileStream = File.OpenWrite(GetExecutionFolder() + "\\Application.log"); _streamWriter = new StreamWriter(_fileStream); } public void WriteLog(string message) { const int MAX_LINES_DESIRED = 1000; StringBuilder formattedMessage = new StringBuilder(); formattedMessage.AppendLine("Date: " + DateTime.Now.ToString());

Dynamically creating a file with node.js and make it available for download

不想你离开。 提交于 2019-12-30 10:08:43
问题 I am building a text editor in Node.js where a user create a file in a textarea. When he is done editing the file, he can push an "export" button that triggers a Jquery function that reads the textarea and post the text on the node.js server. The server should read the information and return a file. I would like to avoid creating a file on the server and servicing it, I'd rather create a file on the fly with streams. I have tried using the following and but that didn't work: exports

Write function not using the seekp value

独自空忆成欢 提交于 2019-12-30 10:06:14
问题 I'm trying to use C++ to write an entry in a specific place in a file so basicly I have ofstream ofs("file.dat", ios::binary | ios::app); ofs.seekp(220, ios::beg); ofs.write((char *)&i, sizeof(i)); But no matter what I do it always write at the end of the file. I suppose this is related to iso::app because according to the documentation app (append) Set the stream's position indicator to the end of the stream before each output operation But if I use ate or nothing it always erases the

Writing a File that has the Name of a Device

爷,独闯天下 提交于 2019-12-30 08:24:11
问题 I have run into something curious. I have a decompiler that extracts information from a binary file. I am extracting a series of objects that I need to write separately to disk as binary files. These objects are graphic models compiled into a library. The objects have names embedded in them and I need to use that name as the file name. I am using : try { // Open file for reading . using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { // Writes a block of bytes