|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Common
{
public class DocumentInfoHandler
{
public bool WriteDocumentInfo(Message docInfo,string uniqueFileID)
{
bool res = false;
string userDefaultDir = Environment.GetEnvironmentVariable("USERPROFILE");
string fullFilePath=userDefaultDir + "\\" + uniqueFileID;
if(File.Exists(fullFilePath))
{
try
{
File.Delete(fullFilePath);
}
catch(Exception ex)
{
}
}
try
{
string[] currentDocInfo = new string[2];
currentDocInfo[0] = docInfo.documentID;
currentDocInfo[1] = docInfo.fileName;
File.WriteAllLines(fullFilePath, currentDocInfo);
res = true;
}
catch (Exception ex)
{
res = false;
}
return res;
}
public Message ReadDocumentInfo(string uniqueFileID)
{
Message docInfo = new Message();
string userDefaultDir = Environment.GetEnvironmentVariable("USERPROFILE");
string fullFilePath = userDefaultDir + "\\" + uniqueFileID;
if (!File.Exists(fullFilePath))
{
docInfo = null;
return docInfo;
}
try
{
string[] info = File.ReadAllLines(fullFilePath);
docInfo.documentID = info[0];
docInfo.fileName = info[1];
docInfo.uniqueID = uniqueFileID;
}
catch(Exception ex)
{
docInfo=null;
}
return docInfo;
}
public bool DeleteDocumentInfo(string uniqueFileID)
{
bool res = false;
string userDefaultDir = Environment.GetEnvironmentVariable("USERPROFILE");
string fullFilePath = userDefaultDir + "\\" + uniqueFileID;
if (File.Exists(fullFilePath))
{
try
{
File.Delete(fullFilePath);
res = true;
}
catch (Exception ex)
{
res = false;
}
}
return res;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.