2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System / System.Net.Mail / LinkedResource.cs
blob6b444452ec509a8b859d3284c63d60f6902fd2a1
1 //
2 // System.Net.Mail.LinkedResource.cs
3 //
4 // Author:
5 // John Luke (john.luke@gmail.com)
6 //
7 // Copyright (C) John Luke, 2005
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #if NET_2_0
33 using System.IO;
34 using System.Net.Mime;
35 using System.Text;
37 namespace System.Net.Mail {
38 public class LinkedResource : AttachmentBase
40 #region Fields
42 Uri contentLink;
44 #endregion // Fields
46 #region Constructors
48 public LinkedResource (string fileName) : base (fileName)
50 if (fileName == null)
51 throw new ArgumentNullException ();
54 public LinkedResource (string fileName, ContentType contentType) : base (fileName, contentType)
56 if (fileName == null)
57 throw new ArgumentNullException ();
60 public LinkedResource (string fileName, string mediaType) : base (fileName, mediaType)
62 if (fileName == null)
63 throw new ArgumentNullException ();
66 public LinkedResource (Stream contentStream) : base (contentStream)
68 if (contentStream == null)
69 throw new ArgumentNullException ();
72 public LinkedResource (Stream contentStream, ContentType contentType) : base (contentStream, contentType)
74 if (contentStream == null)
75 throw new ArgumentNullException ();
78 public LinkedResource (Stream contentStream, string mediaType) : base (contentStream, mediaType)
80 if (contentStream == null)
81 throw new ArgumentNullException ();
84 #endregion // Constructors
86 #region Properties
88 public Uri ContentLink {
89 get { return contentLink; }
90 set { contentLink = value; }
93 #endregion // Properties
95 #region Methods
97 public static LinkedResource CreateLinkedResourceFromString (string content)
99 if (content == null)
100 throw new ArgumentNullException ();
101 MemoryStream ms = new MemoryStream (Encoding.Default.GetBytes (content));
102 LinkedResource lr = new LinkedResource (ms);
103 lr.TransferEncoding = TransferEncoding.QuotedPrintable;
104 return lr;
107 public static LinkedResource CreateLinkedResourceFromString (string content, ContentType contentType)
109 if (content == null)
110 throw new ArgumentNullException ();
111 MemoryStream ms = new MemoryStream (Encoding.Default.GetBytes (content));
112 LinkedResource lr = new LinkedResource (ms, contentType);
113 lr.TransferEncoding = TransferEncoding.QuotedPrintable;
114 return lr;
117 public static LinkedResource CreateLinkedResourceFromString (string content, Encoding contentEncoding, string mediaType)
119 if (content == null)
120 throw new ArgumentNullException ();
121 MemoryStream ms = new MemoryStream (contentEncoding.GetBytes (content));
122 LinkedResource lr = new LinkedResource (ms, mediaType);
123 lr.TransferEncoding = TransferEncoding.QuotedPrintable;
124 return lr;
127 #endregion // Methods
131 #endif // NET_2_0