filestream

how to modify content in filestream while using open xml?

非 Y 不嫁゛ 提交于 2019-12-11 17:39:33
问题 In the code below, I am merging some files together and saving them in the test.docx file. However, before I merg each file, I would like to first replace the text of some content controls which are used as place holders. Can someone show me how to do that? suppose I have one content control in template2 and it is called placeholder1. How can I add text to this placeholder while usig the filestream? string fileName = Path.Combine(@"Docs\templates", "test.docx"); for (int i = 1; i < 3; i++) {

Generating PDF byte array

↘锁芯ラ 提交于 2019-12-11 16:48:20
问题 I have a static method like this and I am using ITextSharp to generate PDF.. public static byte[] createPDF(string htmlstr) { var html = @"<?xml version=""1.0"" encoding=""UTF-8""?> <!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd""> <html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en""> <head> <title>Minimal XHTML 1.0 Document with W3C DTD</title> </head> <body> " + htmlstr + "</body></html>"; // step 1:

C#: looking for file stream seek between 2 length

安稳与你 提交于 2019-12-11 15:28:43
问题 I would like to copy the partial content of a file using FileStream seek. the actual file stream length of the file = 98764 . I want file content between length 200 and 5000 If I am doing fileStream.Seek(200, SeekOrigin.Begin) , then this give me file content from 200 to 98764 , but I want from 200 and 5000 . public static async Task<HttpResponseMessage> Get() { using (var fileStream = new FileStream(@"C:\test\tes1.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var

Stream closed Exception

青春壹個敷衍的年華 提交于 2019-12-11 14:23:59
问题 I'm getting Stream is closed Exception when I'm going to save the uploaded image. I'm tring to preview graphicImage of uploaded image the before save. This operation is working. But I can't save the image. Here is my code: private InputStream in; private StreamedContent filePreview; // getters and setters public void upload(FileUploadEvent event)throws IOException { // Folder Creation for upload and Download File folderForUpload = new File(destination);//for Windows folderForUpload.mkdir();

“ 'System.UnauthorizedAccessException' occurred in mscorlib.dll” while trying to create file in the C:\ drive

我是研究僧i 提交于 2019-12-11 14:18:04
问题 I'm doing this project where I grab some information and save it to a file. While trying to create that file, I always get an System.UnauthorizedAccesssException error. I've tried adding a manifest file and requiring admin, still doesn't work. I've also released it and ran the program through the \bin folder, and it still didn't work. Here is my code: public static void CreateFile(string path, string name) { Debug.WriteLine("Starting to create file..."); string Name = name; string path2 =

Download Files From Resource Library in c# .net

血红的双手。 提交于 2019-12-11 13:36:34
问题 I am developing an application where from several screens user has to download a sample file(excel) to work with. What will be the preferable way to do so. What i am doing is Placing the file in the directory where application is executing and download the files using Application.StartupPath. This does not sounds like a very good solution. As at anytime user could edit the files or delete the files or such things. What i want to do is I want to add all the files in my resources and download

VB.NET FTP Error 550

懵懂的女人 提交于 2019-12-11 12:48:59
问题 I try to upload '.ics' Files to an active FTP Server Namespaces: Imports System Imports System.IO Imports System.Data.OleDb Imports System.Collections Imports Microsoft.VisualBasic Imports System.Net Imports System.Text Code: 'Create a FTP Request Object and Specfiy a Complete Path Dim reqObj As FtpWebRequest = WebRequest.Create(Ziel + "Calendar/" + MitarbeiterNr + ".ics") reqObj.Method = WebRequestMethods.Ftp.UploadFile reqObj.UsePassive = False reqObj.Credentials = New NetworkCredential

Issue while reading special characters from file

别说谁变了你拦得住时间么 提交于 2019-12-11 12:48:10
问题 I am facing an issue while reading a file with special characters. My .txt file has data: I am reading this file using following code: StringBuilder sBuilderString = new StringBuilder(); for (int n; (n = loInputStream.read()) != -1;) { sBuilderString.append((char)n); } This string is now again used to write a file, the issue is that when i write the file, one of these two characters is replaced by some other special character. How can i write code, which is able to read all the special

save an image from ink canvas

喜你入骨 提交于 2019-12-11 11:59:04
问题 I am trying to save an image from ink canvas however it does not create any file after saving, this is my code RenderTargetBitmap rtb = new RenderTargetBitmap( (int)canvas.Width, (int)canvas.Height, 0, 0, PixelFormats.Default); rtb.Render(this.canvas); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(rtb)); using(var file = new FileStream(@"C:\test.jpg", FileMode.Create)) { encoder.Save(file); } however it does not create any file even when I change

How can I elegantly implement multiple string replacements in the same file?

匆匆过客 提交于 2019-12-11 11:22:35
问题 Currently I have some code to replace strings in a file that looks like this: File.WriteAllText(filePath, Regex.Replace(File.ReadAllText(filePath), "( " + column.Key + " )", " " + column.Value + " " )); File.WriteAllText(filePath, Regex.Replace(File.ReadAllText(filePath), "(\\[\"" + column.Key + "\"\\])", "[\"" + column.Value + "\"]" )); However, each replacement opens and closes the file, and it seems that occasionally they run "too fast" and one replacement will not work because the file