Aracılığıyla paylaş


ServerDocument Oluşturucu (array<Byte , String)

Yeni bir örneğini başlatır ServerDocument yüklenebilmesi için belgeyi temsil eden bir bayt dizisi 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 ( _
    bytes As Byte(), _
    fileType As String _
)
public ServerDocument(
    byte[] bytes,
    string fileType
)

Parametreler

  • bytes
    Tür: array<System.Byte[]
    Yüklenecek belgeyi temsil eden bir bayt dizisi.
  • 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

bytes 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.

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 örneğinde ServerDocument(array<Byte[], String) yeni bir oluşturmak için yapıcı ServerDocument gelen .xlsx dosya adı uzantısına sahip bir Excel çalışma kitabı içeren bir bayt dizisi.Örnek daha sonra kullanır Document belgedeki bayt sayısını görüntülemek için özellik.

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 CreateServerDocumentFromByteArray(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
            ' Read the file into a byte array.
            stream = New System.IO.FileStream(documentPath, System.IO.FileMode.Open, _
                System.IO.FileAccess.Read)
            Dim buffer(Fix(stream.Length)) As Byte
            stream.Read(buffer, 0, Fix(buffer.Length))

            ' Display the number of bytes in the document.
            serverDocument1 = New ServerDocument(buffer, "*.xlsx")
            MessageBox.Show("The Document property contains " & _
                serverDocument1.Document.Length.ToString() & " bytes.")
        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 CreateServerDocumentFromByteArray(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;
    System.IO.FileStream stream = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            // Read the file into a byte array.
            stream = new System.IO.FileStream(
                documentPath, System.IO.FileMode.Open,
                System.IO.FileAccess.Read);
            byte[] buffer = new byte[(int)stream.Length];
            stream.Read(buffer, 0, (int)buffer.Length);

            // Display the number of bytes in the document.
            serverDocument1 = new ServerDocument(buffer,
                "*.xlsx");
            MessageBox.Show("The Document property contains " +
                serverDocument1.Document.Length.ToString() +
                " bytes.");
        }
    }
    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ı