Class AttachedFile

AttachedFile class

Represents an attached file.

public class AttachedFile : Node, IOutlineElementChildNode, IPageChildNode, ITaggable

Constructors

NameDescription
AttachedFile()Initializes a new instance of the AttachedFile class.
AttachedFile(string)Initializes a new instance of the AttachedFile class.
AttachedFile(string, Stream)Initializes a new instance of the AttachedFile class.
AttachedFile(string, Stream, ImageFormat)Initializes a new instance of the AttachedFile class.
AttachedFile(string, Stream, Stream, ImageFormat)Initializes a new instance of the AttachedFile class.

Properties

NameDescription
Alignment { get; set; }Gets or sets the alignment.
AlternativeTextDescription { get; set; }Gets or sets a body an alternative text for the icon of the attached file.
AlternativeTextTitle { get; set; }Gets or sets a title of alternative text for the icon of the attached file.
Bytes { get; }Gets the binary data for an embedded file.
Document { get; }Gets the document of the node.
Extension { get; }Gets the extension of an embedded file.
FileName { get; }Gets the name of the embedded file.
FilePath { get; }Gets the path to the original file.
Height { get; }Gets the original height of the embedded file icon.
HorizontalOffset { get; set; }Gets or sets the horizontal offset.
Icon { get; }Gets the binary data for the icon that is associated with the embedded file.
IconExtension { get; }Gets the extension of the icon.
virtual IsComposite { get; }Gets a value indicating whether this node is composite. If true the node can have child nodes.
IsPrintout { get; set; }Gets or sets a value indicating whether the view of the file is printout.
IsSizeSetByUser { get; set; }Gets or sets a value indicating whether the value of the size of the icon was explicitly updated by the user.
LastModifiedTime { get; set; }Gets or sets the last modified time.
MaxHeight { get; set; }Gets or sets the maximum height to display the embedded file icon.
MaxWidth { get; set; }Gets or sets the maximum width to display the embedded file icon.
NextSibling { get; }Gets the next node at the same node tree level.
NodeType { get; }Gets the node type.
ParentNode { get; }Gets the parent node.
ParsingErrorInfo { get; }Gets the data about error that occurred while accessing the file.
PreviousSibling { get; }Gets the previous node at the same node tree level.
Tags { get; }Gets the list of all tags of a paragraph.
Text { get; set; }Gets or sets the text representation of the embedded file. The string MUST NOT contain any characters of the value 10 (line feed) or 13 (carriage return).
VerticalOffset { get; set; }Gets or sets the vertical offset.
Width { get; }Gets the original width of the embedded file icon.

Methods

NameDescription
override Accept(DocumentVisitor)Accepts the visitor of the node.

Examples

Shows how to get content of an attached file.

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Attachments();

// Load the document into Aspose.Note.
Document oneFile = new Document(dataDir + "Sample1.one");

// Get a list of attached file nodes
IList<AttachedFile> nodes = oneFile.GetChildNodes<AttachedFile>();

// Iterate through all nodes
foreach (AttachedFile file in nodes)
{
    // Load attached file to a stream object
    using (Stream outputStream = new MemoryStream(file.Bytes))
    {
        // Create a local file
        using (Stream fileStream = System.IO.File.OpenWrite(String.Format(dataDir + file.FileName)))
        {
            // Copy file stream
            CopyStream(outputStream, fileStream);
        }
    }
}

Shows how to add a file to a document by using filepath.

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Attachments();

// Create an object of the Document class
Document doc = new Document();

// Initialize Page class object
Aspose.Note.Page page = new Aspose.Note.Page(doc);

// Initialize Outline class object
Outline outline = new Outline(doc);

// Initialize OutlineElement class object
OutlineElement outlineElem = new OutlineElement(doc);

// Initialize AttachedFile class object
AttachedFile attachedFile = new AttachedFile(doc,  dataDir + "attachment.txt");

// Add attached file
outlineElem.AppendChildLast(attachedFile);

// Add outline element node
outline.AppendChildLast(outlineElem);

// Add outline node
page.AppendChildLast(outline);

// Add page node
doc.AppendChildLast(page);

dataDir = dataDir + "AttachFileByPath_out.one";
doc.Save(dataDir);

Shows how to add a file from a stream to a document.

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Attachments();

// Create an object of the Document class
Document doc = new Document();

// Initialize Page class object
Aspose.Note.Page page = new Aspose.Note.Page(doc);

// Initialize Outline class object
Outline outline = new Outline(doc);

// Initialize OutlineElement class object
OutlineElement outlineElem = new OutlineElement(doc);

using (var stream = File.OpenRead(dataDir + "icon.jpg"))
{
    // Initialize AttachedFile class object and also pass its icon path
    AttachedFile attachedFile = new AttachedFile(doc, dataDir + "attachment.txt", stream, ImageFormat.Jpeg);

    // Add attached file
    outlineElem.AppendChildLast(attachedFile);
}

// Add outline element node
outline.AppendChildLast(outlineElem);

// Add outline node
page.AppendChildLast(outline);

// Add page node
doc.AppendChildLast(page);

dataDir = dataDir + "AttachFileAndSetIcon_out.one";
doc.Save(dataDir);

See Also