Aracılığıyla paylaş


ServerDocument Oluşturucu (Stream, String)

Yeni bir örneğini başlatır ServerDocument yüklenebilmesi için belgeyi temsil eden bir akış ve belgenin dosya adı uzantısını kullanarak sınıf.

Ad alanı:  Microsoft.VisualStudio.Tools.Applications
Derleme:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll içinde)

Sözdizimi

'Bildirim
Public Sub New ( _
    stream As Stream, _
    fileType As String _
)
public ServerDocument(
    Stream stream,
    string fileType
)

Parametreler

  • fileType
    Tür: System.String
    Depolanan belgenin dosya adı uzantısı bytes parametresi, öncesinde bir nokta (.)— Örneğin, ".xlsx" veya ".docx".

Özel Durumlar

Exception Koşul
ArgumentNullException

stream Parametresi nullnull başvuru (Visual Basic'te Nothing) ya da boş.

-veya-

fileType Parametresi nullnull başvuru (Visual Basic'te Nothing) veya boş ya da tamamen boşluk karakterlerinden oluşur.

ArgumentException

stream Parametre uzunluğu sıfır veya mevcut konumundan akışın sonuna.

UnknownCustomizationFileException

fileType Parametresi tarafından desteklenmeyen bir dosya adı uzantısını belirtir Office için Visual Studio Araçları çalışma zamanı modülü.

DocumentCustomizedWithPreviousRuntimeException

Tarafından belirtilen dosya documentPath ile Visual Studio 2010 Araçları Office çalışma zamanı veya Microsoft Office sistemi için Visual Studio Araçları için oluşturulmamış bir özelleştirme vardır (sürüm 3.0 çalışma zamanı).

Notlar

Bu Oluşturucu bellekte olan bir belgede önbelleğe alınmış verileri veya dağıtım bildirim bilgilere erişmek için kullanın.Bu kurucu kullandığınızda, belge okuma/yazma erişimi ile açılır.

fileType Parametresi yalnızca bayt dizisinde depolanan belge türünü belirlemek için kullanılır.Değeri fileType belge düzeyi özelleştirmeleri için desteklenen dosya türlerinden birini eşleştirilir.Dosyayı açmak için girişimde bulunulmaz.İsteğe bağlı olarak bir tam dosya adı (örneğin, "Workbook1.xlsx") geçirebilirsiniz, ancak bunu yaparsanız, yalnızca dosya adı uzantısı kullanılır.Desteklenen dosya türleri hakkında daha fazla bilgi için bkz: Belge Düzeyi Özelleştirmeler Mimarisi.

Bu Oluşturucu çağrıldıktan sonra belgenin bayt dizisi erişmek için Document özelliği.

Örnekler

Aşağıdaki kod örnek ServerDocument(Stream, String) yeni bir oluşturmak için yapıcı ServerDocument gelen bir FileStream içeren bir Excel çalışma kitabı .xlsx dosya adı uzantısına sahip.Kod daha sonra belgeye iliştirilmiş özelleştirme için dağıtım bildiriminin URL'sini görüntüler.

Bu örnek aşağıdakileri gerektirir:

  • Konsol uygulama projesi veya başka bir Office dışı proje.

  • Aşağıdaki derlemelere başvurular:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.dll (durumunda proje hedefleri .NET Framework 4 veya .NET Framework 4.5).

      veya

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (proje .NET Framework 3.5 hedefliyorsa).

  • Imports(Visual Basic için) veya using için (C#) deyimleri için Microsoft.VisualStudio.Tools.Applications ve Microsoft.VisualStudio.Tools.Applications.Runtime kod dosyanın üst ad.

Private Sub CreateServerDocumentFromStream(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing
    Dim stream As System.IO.FileStream = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            stream = New System.IO.FileStream(documentPath, System.IO.FileMode.Open)
            serverDocument1 = New ServerDocument(stream, "*.xlsx")
            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 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
        If Not (stream Is Nothing) Then
            stream.Close()
        End If
    End Try
End Sub
private void CreateServerDocumentFromStream(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;
    System.IO.FileStream stream = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            stream = new System.IO.FileStream(
                documentPath, System.IO.FileMode.Open);
            serverDocument1 = new ServerDocument(stream,
                "*.xlsx");
            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 (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();
        if (stream != null)
            stream.Close();
    }
}

.NET Framework Güvenliği

Ayrıca bkz.

Başvuru

ServerDocument Sınıf

ServerDocument Fazla Yük

Microsoft.VisualStudio.Tools.Applications Ad Alanı