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


ServerDocument - конструктор (String, FileAccess)

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

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

Синтаксис

'Декларация
Public Sub New ( _
    documentPath As String, _
    access As FileAccess _
)
public ServerDocument(
    string documentPath,
    FileAccess access
)

Параметры

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

Исключения

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

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

ArgumentException

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

FileNotFoundException

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

DocumentNotCustomizedException

В файле, заданном параметром documentPath, нет настройки, а значение access равно System.IO.FileAccess.Read.

DocumentCustomizedWithPreviousRuntimeException

Файл, указанный параметром documentPath, содержит настройку, которая не была создана с помощью Visual Studio 2010 Tools для среды выполнения Office или Visual Studio Tools для системы Microsoft Office (версия среды выполнения 3.0).

UnknownCustomizationFileException

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

Заметки

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

Примеры

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

Для этого примера требуется:

  • Проект консольного приложения или другой проект, не связанный с Office.

  • Ссылки на следующие сборки:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll и Microsoft.VisualStudio.Tools.Applications.Runtime.dll (если проект предназначен для платформы .NET Framework 4).

      или

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll и Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (если проект предназначен для платформы .NET Framework 3.5).

  • Операторы 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();
    }
}

Безопасность платформы .NET Framework

См. также

Ссылки

ServerDocument Класс

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

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