I have filename like this: 一個例子.pdf
I want to save the filename in a SQL Server table and read it from the SQL Server table. How do you do that?
This is the code:
class Bestand
{
public void Add(string filePath, DateTime fileDate, string fileName = "")
{
Bestand bestand = this.CurrentBestand;
if (filePath.Length > 0 && CanReadFile(filePath))
{
Binary bin = new Binary();
bin.Data = new System.Data.Linq.Binary(File.ReadAllBytes(filePath));
bestand.BestandsDatum = fileDate;
bestand.BestandsNaam = String.IsNullOrEmpty(fileName) ? Path.GetFileName(filePath) : Encoding.UTF8.GetBytes(fileName)[0].ToString();
bestand.Binary = bin;
}
}
public void Save(string filePath)
{
byte[] buffer = Data.ToArray();
System.IO.File.WriteAllBytes(filePath, buffer);
}
…
}
and call this to save the file:
documents[0].Add(beFile.Value, dtpDate.Value);
and call this to open the file:
public static void ViewBestand(IBestand bestand)
{
string orgFilepath = Path.Combine(TempDocumentFolder, bestand.FileName);
string filepath = orgFilepath;
int tmpCounter = 0;
while (File.Exists(filepath) && tmpCounter < 100)
{
tmpCounter++;
filepath = Path.Combine(TempDocumentFolder, Path.GetFileNameWithoutExtension(orgFilepath) + "_" + tmpCounter.ToString() + Path.GetExtension(orgFilepath));
}
bestand.Save(filepath);
ViewFile(filepath);
}