Merge pull request #4045 from lambdageek/bug-47867
[mono.git] / mcs / class / System.Web / System.Web.Mail / RelatedBodyPart.cs
index d6389dad4ddec132f3708d281ddcdff2009db635..fd3160da452585ca6e825130319cf6a2d1e9fe87 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
-
+using System.Web;
 namespace System.Web.Mail 
 {
        public class RelatedBodyPart
        {
-               private string id;
-               private string fileName;
+               string id;
+               string fileName;
                
                public RelatedBodyPart (string id, string fileName)
                {
                        this.id = id;
-                       this.fileName = fileName;
+                       if (FileExists (fileName))
+                               this.fileName = fileName;
+                       else
+                               throw new HttpException(500, "Invalid related body part");
                }
                
                public string Name {
@@ -52,6 +54,17 @@ namespace System.Web.Mail
                        get { return fileName; }
                        set { fileName = value; }
                }
+               
+               bool FileExists (string fileName)
+               {
+                       //I am handling local files only . Not sure how URL's
+                       //need to be handled.
+                       try {
+                               System.IO.File.OpenRead (fileName).Close ();
+                               return true;
+                       } catch (Exception) {
+                           return false;
+                       }
+               }
        }
 }
-#endif