System.Web.UI.Control.OpenFile C# (CSharp) Method

OpenFile() protected method

protected OpenFile ( string path ) : Stream
path string
return System.IO.Stream
		protected internal Stream OpenFile (string path)
		{
			try {
				string filePath = Context.Server.MapPath (path);
				return File.OpenRead (filePath);
			}
			catch (UnauthorizedAccessException) {
				throw new HttpException ("Access to the specified file was denied.");
			}
		}

Usage Example

 public MailMessage CreateMailMessage(string recipients, IDictionary replacements, Control owner)
 {
     if (owner == null)
     {
         throw new ArgumentNullException("owner");
     }
     string body = string.Empty;
     string bodyFileName = this.BodyFileName;
     if (!string.IsNullOrEmpty(bodyFileName))
     {
         string path = bodyFileName;
         if (!UrlPath.IsAbsolutePhysicalPath(path))
         {
             path = UrlPath.Combine(owner.AppRelativeTemplateSourceDirectory, path);
         }
         TextReader reader = new StreamReader(owner.OpenFile(path));
         try
         {
             body = reader.ReadToEnd();
         }
         finally
         {
             reader.Close();
         }
     }
     return this.CreateMailMessage(recipients, replacements, body, owner);
 }
All Usage Examples Of System.Web.UI.Control::OpenFile