Поделиться через


ServerDocument Конструктор (String, FileAccess) (2007 System)

Обновлен: Ноябрь 2007

Инициализирует новый экземпляр класса ServerDocument с помощью полного пути к документу, который требуется загрузить, а также значения, обозначающего доступ к файлу документа.

Пространство имен:  Microsoft.VisualStudio.Tools.Applications
Сборка:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0 (в Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll)

Синтаксис

'Декларация
Public Sub New ( _
    documentPath As String, _
    access As FileAccess _
)
'Применение
Dim documentPath As String
Dim access As FileAccess

Dim instance As New ServerDocument(documentPath, _
    access)
public ServerDocument(
    string documentPath,
    FileAccess access
)

Параметры

  • documentPath
    Тип: System.String
    Полный путь к документу, который требуется загрузить.
  • access
    Тип: System.IO.FileAccess
    Значение, указывающее доступ к файлу документа.

Исключения

Исключение Условие
ArgumentNullException

Параметр documentPath равен nullссылка null (Nothing в Visual Basic), пуст или содержит только пробелы.

ArgumentException

Значение access равно Write.

FileNotFoundException

Файл, заданный в параметре documentPath, не существует.

DocumentNotCustomizedException

В файле, заданном с помощью параметра documentPath, нет настройки Visual Studio Tools for Office, а значение access равно Read.

DocumentCustomizedWithPreviousRuntimeException

Файл, заданный в параметре documentPath, имеет настройку, созданную в предыдущей версии среды выполнения Visual Studio Tools for Office.

UnknownCustomizationFileException

Visual Studio Tools for Office не поддерживает расширение имени файла, заданное в параметре documentPath.

Заметки

Этот конструктор используется для доступа к кэшированным данным или данным манифеста развертывания в документе, находящемся на диске, если требуется открыть документ с правами доступа только для чтения или только для записи. По умолчанию, другие конструкторы ServerDocument открывают документ с правом доступа на чтение/запись.

Примеры

В следующем примере кода показывается, как использовать конструктор ServerDocument(String, FileAccess) для создания нового объекта ServerDocument, который загружает указанный документ только для чтения. Затем в примере отображается URL-адрес манифеста развертывания для настройки Visual Studio Tools for Office, прикрепленной к документу.

Для этого примера требуются ссылки на сборки Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll, Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll и операторы Imports (в Visual Basic) или using (в C#) для пространств имен Microsoft.VisualStudio.Tools.Applications и Microsoft.VisualStudio.Tools.Applications.Runtime в начале файла с кодом.

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();
    }
}

Разрешения

См. также

Ссылки

ServerDocument Класс

ServerDocument - члены

ServerDocument - перегрузка

Microsoft.VisualStudio.Tools.Applications - пространство имен