ServerDocument Constructor (String, FileAccess)

Initializes a new instance of the ServerDocument class using the full path of the document to be loaded and a value that indicates the file access for the document.

Namespace:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Syntax

'Declaration
Public Sub New ( _
    documentPath As String, _
    access As FileAccess _
)
public ServerDocument(
    string documentPath,
    FileAccess access
)

Parameters

  • documentPath
    Type: System.String

    The full path of the document to be loaded.

Exceptions

Exception Condition
ArgumentNullException

The documentPath parameter is nulla null reference (Nothing in Visual Basic) or empty or consists entirely of white space characters.

ArgumentException

The value of access is System.IO.FileAccess.Write.

FileNotFoundException

The file specified by documentPath does not exist.

DocumentNotCustomizedException

The file specified by the documentPath parameter does not have a customization, and the value of access is System.IO.FileAccess.Read.

DocumentCustomizedWithPreviousRuntimeException

The file specified by documentPath has a customization that was not created with the Visual Studio 2010 Tools for Office Runtime or the Visual Studio Tools for the Microsoft Office system (version 3.0 Runtime).

UnknownCustomizationFileException

The file specified by documentPath has a file name extension that is not supported by the Visual Studio Tools for Office runtime.

Remarks

Use this constructor to access the cached data or deployment manifest information in a document that is on disk if you want to open the document with read-only or write-only access. By default, the other ServerDocument constructors open the document with read/write access.

Examples

The following code example uses the ServerDocument(String, FileAccess) constructor to create a new ServerDocument that loads a specified document with read-only access. The code then displays the URL of the deployment manifest for the customization that is attached to the document.

This example requires:

  • A console application project or some other non-Office project.

  • References to the following assemblies:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.dll (if the project targets the .NET Framework 4 or the .NET Framework 4.5).

      or

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (if the project targets the .NET Framework 3.5).

  • Imports (for Visual Basic) or using (for C#) statements for Microsoft.VisualStudio.Tools.Applications and Microsoft.VisualStudio.Tools.Applications.Runtime namespaces at the top of your code file.

Private Sub CreateServerDocumentReadOnly(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing 

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            serverDocument1 = New ServerDocument(documentPath, System.IO.FileAccess.Read)
            MessageBox.Show("The URL of the deployment manifest is: " & vbLf & _
                serverDocument1.DeploymentManifestUrl.ToString())
        End If 

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As DocumentNotCustomizedException
        System.Windows.Forms.MessageBox.Show("The specified document does not " & _
            "have a customization.")
    Catch ex As UnknownCustomizationFileException
        System.Windows.Forms.MessageBox.Show("The specified document has a file " & _
            "extension that is not supported by Visual Studio Tools for Office.")
    Finally 
        If Not (serverDocument1 Is Nothing) Then
            serverDocument1.Close()
        End If 
    End Try 
End Sub
private void CreateServerDocumentReadOnly(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            serverDocument1 = new ServerDocument(documentPath,
                System.IO.FileAccess.Read);
            MessageBox.Show("The URL of the deployment manifest is: \n" +
                serverDocument1.DeploymentManifestUrl.ToString());
        }
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (DocumentNotCustomizedException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not " +
            "have a customization.");
    }
    catch (UnknownCustomizationFileException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document has a file " +
            "extension that is not supported by Visual Studio Tools for Office.");
    }
    finally
    {
        if (serverDocument1 != null)
            serverDocument1.Close();
    }
}

.NET Framework Security

See Also

Reference

ServerDocument Class

ServerDocument Overload

Microsoft.VisualStudio.Tools.Applications Namespace