IResource.ContentType Property

IT Hit WebDAV for .NET

Gets the media type of the resource.

[Visual Basic]
Property ContentType As String
[C#]
string ContentType {get;}

Property Value

The MIME type of the resource.

Remarks

The mime-type provided by this property is returned in a Content-Type header with GET request.

When deciding which action to perform when downloading a file some WebDAV clients and browsers (such as Internet Explorer) rely on file extension, while others (such as Firefox) rely on Content-Type header returned by server. For identical behavior in all browsers and WebDAV clients your server must return a correct mime-type with a requested file.

Example

    public string ContentType
    {
        get
        {
            string contentType = "";

            SqlConnection conn = new SqlConnection(connStr);
            SqlCommand cmd;
            SqlDataReader reader = null;
            conn.Open();
            
            try
            {
                cmd = conn.CreateCommand();
                cmd.CommandText = "SELECT ContentType FROM Repository WHERE ID = @ID";
                cmd.Parameters.Add("@ID", SqlDbType.Int).Value = ID;
                reader = cmd.ExecuteReader();
                reader.Read();
                if(!reader.IsDBNull(reader.GetOrdinal("ContentType")))
                    contentType = reader.GetString(reader.GetOrdinal("ContentType"));
            }
            finally
            {
                if(reader != null) reader.Close();
                conn.Close();
            }

            if (string.IsNullOrEmpty(contentType))
             contentType = 
                 MimeType.GetMimeType(System.IO.Path.GetExtension(this.fName))
                 ?? "application/octet-stream";
            return contentType;
        }
    }
 

See Also

IResource Interface | ITHit.WebDAV.Server Namespace