ServerDocument – konstruktor (array<Byte , String)
Inicializuje novou instanci ServerDocument třídy pomocí bajtové pole, která představuje dokument má být načten a příponu názvu souboru dokumentu.
Obor názvů: Microsoft.VisualStudio.Tools.Applications
Sestavení: Microsoft.VisualStudio.Tools.Applications.ServerDocument (v Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)
Syntaxe
'Deklarace
Public Sub New ( _
bytes As Byte(), _
fileType As String _
)
public ServerDocument(
byte[] bytes,
string fileType
)
Parametry
- bytes
Typ: array<System.Byte[]
Bajtové pole představuje dokument má být načten.
- fileType
Typ: System.String
Přípona názvu souboru uloženého v dokumentu bytes parametr předchází tečka (.)– například "XLSX" nebo ".docx".
Výjimky
Výjimka | Podmínka |
---|---|
ArgumentNullException | bytes Je parametr nullodkaz Null (Nothing v jazyce Visual Basic) nebo prázdná. -nebo- fileType Je parametr nullodkaz Null (Nothing v jazyce Visual Basic) nebo prázdné nebo je celá tvořena bílých znaků. |
UnknownCustomizationFileException | fileType Parametr určuje příponu souboru, která není podporována Visual Studio Tools for Office runtime. |
DocumentCustomizedWithPreviousRuntimeException | Určený soubor documentPath má vlastní nastavení, který byl vytvořen pomocí Visual Studio 2010 Tools for Office Runtime nebo Visual Studio Tools pro systém Microsoft Office (verze 3.0 Runtime). |
Poznámky
Použijte tento konstruktor přístup dat nebo nasazení manifestu informace v mezipaměti v dokumentu, který je již v paměti. Při použití tohoto konstruktoru dokument otevřít s přístupem pro čtení i zápis.
fileType Parametr se používá pouze k určení typu dokumentu uloženy v byte array. Hodnota fileType je mapován na jeden z typů souborů podporované pro úpravy úrovni dokumentu. Bez pokusu otevřít soubor. Můžete volitelně předáte název souboru (například "Workbook1.xlsx"), ale pokud to uděláte, je použit pouze příponu názvu souboru. Další informace o typech souborů podporovaných Architecture of Document-Level Customizations.
Po volání konstruktoru tento přístup bajtové pole dokumentu, Document vlastnost.
Příklady
Následující kód například použití ServerDocument(array<Byte[], String) konstruktor pro vytvoření nového ServerDocument z bajtové pole obsahující sešit aplikace Excel s XLSX soubor název rozšíření. Příklad poté používá Document vlastností zobrazení počtu bajtů v dokumentu.
Tento příklad vyžaduje:
Projekt aplikace konzoly nebo některé jiné-Office project.
Odkazy na následující sestavení:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (pokud cíle projektu .NET Framework 4).
nebo
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (pokud cíle projektu.NET Framework 3.5).
Imports(pro Visual Basic) nebo using (pro C#) pro příkazy Microsoft.VisualStudio.Tools.Applications a Microsoft.VisualStudio.Tools.Applications.Runtime obory názvů v horní části souboru kódu.
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();
}
}
Zabezpečení rozhraní .NET Framework
- Plná důvěra přímému volajícímu. Částečně zabezpečený kód nemůže tento člen použít. Další informace naleznete v tématu Používání knihoven z částečně důvěryhodného kódu.