Save Ascii content to DocAscii
This commit is contained in:
		@@ -6,6 +6,7 @@ using Csla;
 | 
			
		||||
using Csla.Data;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Data.SqlClient;
 | 
			
		||||
using EPocalipse.IFilter;
 | 
			
		||||
 | 
			
		||||
namespace VEPROMS.CSLA.Library
 | 
			
		||||
{
 | 
			
		||||
@@ -19,6 +20,45 @@ namespace VEPROMS.CSLA.Library
 | 
			
		||||
				return _LibTitle;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		public void UpdateDocAscii(string fileName)
 | 
			
		||||
		{
 | 
			
		||||
			try
 | 
			
		||||
			{
 | 
			
		||||
				DocAscii = null;
 | 
			
		||||
				// Opening the file directly gives a sharing violation.
 | 
			
		||||
				// Therefore, the file is copied and the copy is used and then deleted.
 | 
			
		||||
				FileInfo myFile = new FileInfo(fileName);
 | 
			
		||||
				FileInfo tempFile = new FileInfo(myFile.DirectoryName + "\\tmp_" + myFile.Name);
 | 
			
		||||
				myFile.CopyTo(tempFile.FullName); // Copy to the temporary file
 | 
			
		||||
				using (FilterReader reader = new FilterReader(tempFile.FullName)) // Open the IFilter Reader
 | 
			
		||||
				{
 | 
			
		||||
					DocAscii = FixString(reader.ReadToEnd()); // Read the ascii text
 | 
			
		||||
					reader.Close(); // Close the reader
 | 
			
		||||
				}
 | 
			
		||||
				tempFile.Delete();
 | 
			
		||||
			}
 | 
			
		||||
			catch (Exception ex)
 | 
			
		||||
			{
 | 
			
		||||
				// Handle exceptions
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		/// <summary>
 | 
			
		||||
		/// FixString processes the string returned and changes any symbols (0xF0??) to normal characters
 | 
			
		||||
		/// </summary>
 | 
			
		||||
		/// <param name="str"></param>
 | 
			
		||||
		/// <returns></returns>
 | 
			
		||||
		private static string FixString(string str)
 | 
			
		||||
		{
 | 
			
		||||
			StringBuilder results = new StringBuilder();
 | 
			
		||||
			foreach (char c in str)
 | 
			
		||||
			{
 | 
			
		||||
				if ((c & 0xFF00) == 0xF000)
 | 
			
		||||
					results.Append((char)(c & 0xFF));
 | 
			
		||||
				else
 | 
			
		||||
					results.Append((char)(c));
 | 
			
		||||
			}
 | 
			
		||||
			return results.ToString();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	public partial class DocumentInfo
 | 
			
		||||
	{
 | 
			
		||||
@@ -234,7 +274,7 @@ namespace VEPROMS.CSLA.Library
 | 
			
		||||
			{
 | 
			
		||||
				if (_MyDocument != null)
 | 
			
		||||
				{
 | 
			
		||||
					_MyFile = new FileInfo(string.Format(@"{0}\tmp_{1}{2}.{3}", TemporaryFolder, MyDocument.DocID, Unique, Extension));
 | 
			
		||||
					_MyFile = new FileInfo(string.Format(@"{0}\tmp_{1}{2}{3}", TemporaryFolder, MyDocument.DocID, Unique, MyDocument.FileExtension));
 | 
			
		||||
					FileStream fs = _MyFile.Create();
 | 
			
		||||
					fs.Write(MyDocument.DocContent, 0, MyDocument.DocContent.Length);
 | 
			
		||||
					fs.Close();
 | 
			
		||||
@@ -266,7 +306,9 @@ namespace VEPROMS.CSLA.Library
 | 
			
		||||
			Byte[] buf = new byte[_MyFile.Length];
 | 
			
		||||
			fs.Read(buf,0,buf.Length);
 | 
			
		||||
			fs.Close();
 | 
			
		||||
			doc.FileExtension = MyFile.Extension;
 | 
			
		||||
			doc.DocContent = buf;
 | 
			
		||||
			doc.UpdateDocAscii(_MyFile.FullName);
 | 
			
		||||
			doc.UserID = Environment.UserName;
 | 
			
		||||
			doc.DTS = _MyFile.LastWriteTime;
 | 
			
		||||
			doc.Save();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user