Class McHttpPostedFile

Provides a way to access individual files that have been uploaded by a client.

Inheritance
System.Object
McHttpPostedFile
Implements
System.IDisposable
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Mediachase.FileUploader.Web
Assembly: Mediachase.FileUploader.dll
Version: 10.8.0
Syntax
public class McHttpPostedFile : IDisposable
Remarks

The McHttpPostedFile class is similar to standard ASP .NET class System.Web.HttpPostedFile. But he recognizes an active marker.

Constructors

McHttpPostedFile(HttpPostedFile)

Initializes a new instance of the McHttpPostedFile class to the value indicated by a System.Web.HttpPostedFile object.

Declaration
public McHttpPostedFile(HttpPostedFile httpPostedFile)
Parameters
Type Name Description
System.Web.HttpPostedFile httpPostedFile

The System.Web.HttpPostedFile object.

Properties

ContentLength

Gets the size in bytes of an uploaded file.

Declaration
public int ContentLength { get; }
Property Value
Type Description
System.Int32

The length of the file.

ContentType

Gets the MIME content type of a file sent by a client.

Declaration
public string ContentType { get; }
Property Value
Type Description
System.String

The MIME content type of the uploaded file.

FileName

Gets the file name of the file on the client's computer (for example "Test.txt").

Declaration
public string FileName { get; }
Property Value
Type Description
System.String

The name of the client's file.

FullyQualifiedFileName

Gets the fully-qualified name of the file on the client's computer (for example "C:\MyFiles\Test.txt").

Declaration
public string FullyQualifiedFileName { get; }
Property Value
Type Description
System.String

The fully-qualified name of the client's file.

InputStream

Gets a Stream object which points to an uploaded file to prepare for reading the contents of the file.

Declaration
public Stream InputStream { get; }
Property Value
Type Description
System.IO.Stream

A System.IO.Stream pointing to a file.

Methods

Dispose()

Releases the resources used by the McHttpPostedFile.

Declaration
public void Dispose()

MoveTo(String)

Moves a specified file to a new location from the temporary folder.

Declaration
public void MoveTo(string destFileName)
Parameters
Type Name Description
System.String destFileName

The name of the saved file.

Remarks

The method moves an incoming file from the temporary folder to a new location. If you use a HDD file storage, MoveTo method will increase performance and decrease a disk space requirement.

To invoke MoveTo(String) method you must turn on an incoming file optimization.

Note: You can execute MoveTo method only once.

Exceptions
Type Condition
System.NotSupportedException

If incoming file optimization turn off.

SaveAs(String)

Saves the contents of an uploaded file.

Declaration
public void SaveAs(string filename)
Parameters
Type Name Description
System.String filename

The name of the saved file.

SaveAs(String, String, String, SqlParameter[])

Saves the contents of an uploaded file into MS SQL database.

Declaration
public void SaveAs(string ConnectionString, string TableName, string ColumnName, params SqlParameter[] PrimaryKeys)
Parameters
Type Name Description
System.String ConnectionString

A sql connection string that includes the source database name, and other parameters needed to establish the initial connection. The default value is an empty string.

System.String TableName

A table name for the table that the current file stream will encapsulate.

System.String ColumnName

A column name for the column that the current file stream will encapsulate.

System.Data.SqlClient.SqlParameter[] PrimaryKeys

A primary keys collection for the row that the current file stream will encapsulate.

Examples

Example saves a new file into MS SQL database named File with FileId:int and Data:image columns.

private void btnSubmit_ServerClick(object sender, System.EventArgs e)
{
	if(McFileUp.PostedFile!=null)
	{
		int FileId = 0;

		//TODO: Create a new record and assign FileId variable.

		McFileUp.PostedFile.SaveAs("Data source=(local);Initial catalog=TestDB;User Id=sa;Password=","File","Data",new SqlParameter("@FileId",FileId));
	}
}

Implements

System.IDisposable