Questions tagged [writeallbytes]

9 questions
43
votes
2 answers

byte array to pdf

I am trying to convert content of a file stored in a sql column to a pdf. I use the following piece of code: byte[] bytes; BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, fileContent); bytes =…
blue piranha
  • 3,706
  • 13
  • 57
  • 98
1
vote
0 answers

Pdf export is corupted

I'm trying to export a pdf/dox document. I have the byte[] array and I tried these 2 variations that i found on the internet: var generalPath = "generalPath"; // returns the pdf byte array var pdfData =…
Sami
  • 141
  • 2
  • 10
1
vote
1 answer

How to use File.WriteAllBytes() of C# to write on mounted drives?

I like to use System.IO.File.WriteAllBytes() to keep things simple. But it seems, that this method can not be used everywhere. To write on my local system it works fine. But when I use System.IO.File.WriteAllBytes() to write on a Windows share it…
koalabruder
  • 2,794
  • 9
  • 33
  • 40
0
votes
1 answer

System.IO.File.WriteAllBytes issue when used for uploading .docx document

I have code like this to accept file upload from Web UI: byte[] addBytes = new byte[] { 45, 45 }; var uploadedFiles = this.HttpContext.Request.Form.Files; foreach (var uploadedFile in uploadedFiles) { …
Yogi
  • 410
  • 4
  • 16
0
votes
0 answers

PowerShell [io.file]::WriteAllBytes() - writing then using a file produces the error "used by another process"

In PowerShell 7.3.4, I'm making a web request, writing the response content to a file, then forwarding the file via another web request. $response1 = Invoke-WebRequest @getParam [io.file]::WriteAllBytes(($local + $filename),…
0
votes
0 answers

Why am I getting Access Denied when writing files to a network path when my user account can create files

System.IO.File.WriteAllBytes(NetworkPath, Encoding.UTF8.GetBytes(stringBuilder.ToString())); When running this code in Visual Studio, I get Access Denied. However if I navigate to Network Path with File Explorer, I can right click and create Files…
software is fun
  • 7,286
  • 18
  • 71
  • 129
0
votes
0 answers

System.UnauthorizedAccessException Message=Access to the path "/C:\Users\user\Desktop\C\dok.txt" is denied

I'm trying to export data to PC local drive from a C# xamarin app. Even as an administrator, I have the same problem as in the title, no matter if the file exist or not... code below, x,y are List : var csv = new StringBuilder(); …
misza
  • 1
0
votes
0 answers

Properly editing a text or source file from C#/.NET

The typical way to edit a text or source file from code is to read the file using File.ReadAllLines or File.ReadAllText, make your changes, and then write it out using WriteAllLines or WriteAllText. However, if you were to open the text file (say…
-2
votes
1 answer

Xamarin File.WriteAllBytes the method does not write data

Here is my code: string f = GetRefInfoServise.GetRefInfo("GA"); byte[] data = System.Convert.FromBase64String(f); var backingFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),…