Some image files contain metadata that you can read to determine features of the image. Like, a digital photograph might contain metadata that you can read to determine the Author,Title and Keywords of the image.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageMetaData.aspx.cs" Inherits="ImageMetaData" %>
Untitled Page
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DSOFile;
public partial class ImageMetaData : System.Web.UI.Page
{
OleDocumentPropertiesClass oDocument;
string strImgName = string.Empty;
string strImgPath = string.Empty;
string strImgTitle = string.Empty;
string strImgAuthor = string.Empty;
string strImgSubject = string.Empty;
string strImgCompany = string.Empty;
string strImgComments = string.Empty;
string strImgApplication = string.Empty;
string strImgVersion = string.Empty;
string strImgCategory = string.Empty;
string strImgKeywords = string.Empty;
string strImgManager = string.Empty;
string strImgLastSavedBy = string.Empty;
string strImgByteCount = string.Empty;
string strImgDateCreated = string.Empty;
string strImgRevisionnum = string.Empty;
string strImgHeight = string.Empty;
string strImgWidth = string.Empty;
string strImgHResolution = string.Empty;
string strImgVResolution = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
OpenDocumentProperties(FileUpload1.PostedFile.FileName.ToString());
sb.Append("
");
Label1.Text = sb.ToString();
}
protected void OpenDocumentProperties(string strFile)
{
try
{
DSOFile.SummaryProperties oSummProps;
string strTmp = string.Empty;
oDocument = new DSOFile.OleDocumentPropertiesClass();
oDocument.Open(strFile, false, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
oSummProps = oDocument.SummaryProperties;
strImgName = oDocument.Name;
strImgPath = oDocument.Path;
if (oSummProps.Author == "" || oSummProps.Comments == "" || oSummProps.Title == "" || oSummProps.Keywords == "")
{
strImgTitle = "All";
}
else
{
strImgTitle = oSummProps.Title;
}
if (oSummProps.Author == "")
{
strImgAuthor = "Unknown";
}
else
{
strImgAuthor = oSummProps.Author;
}
strImgSubject = oSummProps.Subject;
strImgCompany = oSummProps.Company;
strImgComments = oSummProps.Comments;
strImgApplication = oSummProps.ApplicationName;
strImgVersion = oSummProps.Version;
strImgCategory = oSummProps.Category;
strImgKeywords = "," + oSummProps.Keywords.ToString() + ",";
strImgManager = oSummProps.Manager;
strImgLastSavedBy = oSummProps.LastSavedBy;
strImgByteCount = oSummProps.ByteCount.ToString();
if (oSummProps.DateCreated != null)
{
strImgDateCreated = oSummProps.DateCreated.ToString();
}
else
{
strImgDateCreated = "";
}
strImgRevisionnum = oSummProps.RevisionNumber;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageMetaData.aspx.cs" Inherits="ImageMetaData" %>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DSOFile;
public partial class ImageMetaData : System.Web.UI.Page
{
OleDocumentPropertiesClass oDocument;
string strImgName = string.Empty;
string strImgPath = string.Empty;
string strImgTitle = string.Empty;
string strImgAuthor = string.Empty;
string strImgSubject = string.Empty;
string strImgCompany = string.Empty;
string strImgComments = string.Empty;
string strImgApplication = string.Empty;
string strImgVersion = string.Empty;
string strImgCategory = string.Empty;
string strImgKeywords = string.Empty;
string strImgManager = string.Empty;
string strImgLastSavedBy = string.Empty;
string strImgByteCount = string.Empty;
string strImgDateCreated = string.Empty;
string strImgRevisionnum = string.Empty;
string strImgHeight = string.Empty;
string strImgWidth = string.Empty;
string strImgHResolution = string.Empty;
string strImgVResolution = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
OpenDocumentProperties(FileUpload1.PostedFile.FileName.ToString());
sb.Append("
Author | Subject | Title |
---|---|---|
");
sb.Append(strImgAuthor); sb.Append(" | ");
");
sb.Append(strImgSubject); sb.Append(" | ");
");
sb.Append(strImgTitle); sb.Append(" | ");
Label1.Text = sb.ToString();
}
protected void OpenDocumentProperties(string strFile)
{
try
{
DSOFile.SummaryProperties oSummProps;
string strTmp = string.Empty;
oDocument = new DSOFile.OleDocumentPropertiesClass();
oDocument.Open(strFile, false, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
oSummProps = oDocument.SummaryProperties;
strImgName = oDocument.Name;
strImgPath = oDocument.Path;
if (oSummProps.Author == "" || oSummProps.Comments == "" || oSummProps.Title == "" || oSummProps.Keywords == "")
{
strImgTitle = "All";
}
else
{
strImgTitle = oSummProps.Title;
}
if (oSummProps.Author == "")
{
strImgAuthor = "Unknown";
}
else
{
strImgAuthor = oSummProps.Author;
}
strImgSubject = oSummProps.Subject;
strImgCompany = oSummProps.Company;
strImgComments = oSummProps.Comments;
strImgApplication = oSummProps.ApplicationName;
strImgVersion = oSummProps.Version;
strImgCategory = oSummProps.Category;
strImgKeywords = "," + oSummProps.Keywords.ToString() + ",";
strImgManager = oSummProps.Manager;
strImgLastSavedBy = oSummProps.LastSavedBy;
strImgByteCount = oSummProps.ByteCount.ToString();
if (oSummProps.DateCreated != null)
{
strImgDateCreated = oSummProps.DateCreated.ToString();
}
else
{
strImgDateCreated = "";
}
strImgRevisionnum = oSummProps.RevisionNumber;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
}
}
}