I have converted a PDF to byte[]. I then converted that to string since it specifically to be saved in the database as nvarchar(MAX). I would however like to know how to convert it to string literal verbatim (following the format of @"text here") to enable me to escape the characters present in the string so that it can be inserted into the database.
Any help would be much appreciated!Code:protected void SavePDFtoDB() { // Save PDF to byte[] mBytePDF = File.ReadAllBytes(msPath); // Convert byte[] to string String contents = ByteArrayToString(mBytePDF); // Save PDF in Database in form of string MainTable lMainTable = new MainTable(); lMainTable.Date = DateTime.Now; lMainTable.Archive = 1; lMainTable.Text = @contents; // PROBLEM: Trying to convert to string literal verbatim SData.mWebService.setMainTable(lMainTable); } private string ByteArrayToString(byte[] arr) { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); return enc.GetString(arr); }




Reply With Quote
