xavehoo
/
XAF_how-to-store-file-attachments-in-the-file-system-instead-of-the-database-xpo-e965
Public
forked from DevExpress-Examples/XAF_how-to-store-file-attachments-in-the-file-system-instead-of-the-database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileSystemLinkObject.cs
62 lines (61 loc) · 2.29 KB
/
FileSystemLinkObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.IO;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using System.ComponentModel;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
namespace FileSystemData.BusinessObjects {
/// <summary>
/// This class enables you to add soft links to real files instead of saving their contents to the database. It is intended for use in Windows Forms applications only.
/// </summary>
[DefaultProperty("FileName")]
public class FileSystemLinkObject : BaseObject, IFileData, IEmptyCheckable, ISupportFullName {
public FileSystemLinkObject(Session session) : base(session) { }
#region IFileData Members
[Size(260), Custom("AllowEdit", "False")]
public string FileName {
get { return GetPropertyValue<string>("FileName"); }
set { SetPropertyValue("FileName", value); }
}
void IFileData.Clear() {
Size = 0;
FileName = string.Empty;
}
//Dennis: Fires when uploading a file.
void IFileData.LoadFromStream(string fileName, Stream source) {
Size = (int)source.Length;
FileName = fileName;
}
//Dennis: Fires when saving or opening a file.
void IFileData.SaveToStream(Stream destination) {
try {
if (destination == null)
FileSystemDataModule.OpenFileWithDefaultProgram(FullName);
else
FileSystemDataModule.CopyFileToStream(FullName, destination);
} catch (Exception exc) {
throw new UserFriendlyException(exc);
}
}
[Persistent]
public int Size {
get { return GetPropertyValue<int>("Size"); }
private set { SetPropertyValue<int>("Size", value); }
}
#endregion
#region IEmptyCheckable Members
public bool IsEmpty {
get { return !File.Exists(FullName); }
}
#endregion
#region ISupportFullName Members
[Size(260), Custom("AllowEdit", "False")]
public string FullName {
get { return GetPropertyValue<string>("FullName"); }
set { SetPropertyValue<string>("FullName", value); }
}
#endregion
}
}