ServerDocument Konstruktory
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Przeciążenia
ServerDocument(String) |
Inicjuje ServerDocument nowe wystąpienie klasy przy użyciu pełnej ścieżki dokumentu do załadowania. |
ServerDocument(Byte[], String) |
Inicjuje nowe wystąpienie ServerDocument klasy przy użyciu tablicy bajtów, która reprezentuje dokument do załadowania i rozszerzenie nazwy pliku dokumentu. |
ServerDocument(Stream, String) |
Inicjuje nowe wystąpienie ServerDocument klasy przy użyciu strumienia reprezentującego dokument do załadowania i rozszerzenia nazwy pliku dokumentu. |
ServerDocument(String, FileAccess) |
Inicjuje nowe wystąpienie ServerDocument klasy przy użyciu pełnej ścieżki dokumentu do załadowania i wartości wskazującej dostęp do pliku dla dokumentu. |
ServerDocument(String)
Inicjuje ServerDocument nowe wystąpienie klasy przy użyciu pełnej ścieżki dokumentu do załadowania.
public:
ServerDocument(System::String ^ documentPath);
public ServerDocument (string documentPath);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : string -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (documentPath As String)
Parametry
- documentPath
- String
Pełna ścieżka dokumentu do załadowania.
Wyjątki
Parametr documentPath
jest null
pusty lub składa się całkowicie z białych znaków.
Plik określony przez documentPath
nie istnieje.
Plik określony przez documentPath
program ma dostosowanie, które nie zostało utworzone za pomocą narzędzi Visual Studio 2010 Tools for Office Runtime lub Visual Studio Tools dla systemu Microsoft Office (wersja 3.0 Runtime).
Plik określony przez documentPath
ma rozszerzenie nazwy pliku, które nie jest obsługiwane przez środowisko uruchomieniowe Visual Studio Tools dla pakietu Office.
Przykłady
Poniższy przykład kodu używa konstruktora ServerDocument(String) do utworzenia nowego ServerDocument , który ładuje określony dokument. W przykładzie zostanie wyświetlony adres URL manifestu wdrożenia dla dostosowania dołączonego do dokumentu.
Ten przykład wymaga:
Projekt aplikacji konsoli lub innych projektów nienależących do pakietu Office.
Odwołania do następujących zestawów:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jeśli projekt jest przeznaczony dla .NET Framework 4 lub .NET Framework 4.5).
lub
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (jeśli projekt jest przeznaczony dla programu.NET Framework 3.5).
Imports
(dla języka Visual Basic) lubusing
(w przypadku języka C#) instrukcje dla Microsoft.VisualStudio.Tools.Applications przestrzeni nazw i Microsoft.VisualStudio.Tools.Applications.Runtime w górnej części pliku kodu.
private void CreateServerDocumentFromPath(string documentPath)
{
int runtimeVersion = 0;
ServerDocument serverDocument1 = null;
try
{
runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
if (runtimeVersion == 3)
{
serverDocument1 = new ServerDocument(documentPath);
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();
}
}
Private Sub CreateServerDocumentFromPath(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)
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
End Try
End Sub
Uwagi
Użyj tego konstruktora, aby uzyskać dostęp do buforowanych danych lub informacji manifestu wdrożenia w dokumencie, który znajduje się na dysku. W przypadku korzystania z tego konstruktora określony dokument jest otwierany z dostępem do odczytu/zapisu.
Dotyczy
ServerDocument(Byte[], String)
Inicjuje nowe wystąpienie ServerDocument klasy przy użyciu tablicy bajtów, która reprezentuje dokument do załadowania i rozszerzenie nazwy pliku dokumentu.
public:
ServerDocument(cli::array <System::Byte> ^ bytes, System::String ^ fileType);
public ServerDocument (byte[] bytes, string fileType);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : byte[] * string -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (bytes As Byte(), fileType As String)
Parametry
- bytes
- Byte[]
Tablica bajtów reprezentująca dokument do załadowania.
- fileType
- String
Rozszerzenie nazwy pliku dokumentu przechowywanego w parametrze bytes
poprzedzonym kropką (.) — na przykład ".xlsx" lub ".docx".
Wyjątki
Parametr bytes
jest lub pusty.-or-Parametr fileType
jest null
null
pusty lub składa się całkowicie z białych znaków.
Parametr fileType
określa rozszerzenie nazwy pliku, które nie jest obsługiwane przez środowisko uruchomieniowe Visual Studio Tools dla pakietu Office.
Plik określony przez documentPath
program ma dostosowanie, które nie zostało utworzone za pomocą narzędzi Visual Studio 2010 Tools for Office Runtime lub Visual Studio Tools dla systemu Microsoft Office (wersja 3.0 Runtime).
Przykłady
Poniższy przykład kodu używa konstruktora [ServerDocument (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.%23ctor%28System.Byte%5B%5D%2C KonstruktorSystem.String%29> do utworzenia nowego konstruktora [ServerDocument (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument> z tablicy bajtów zawierającej skoroszyt programu Excel z rozszerzeniem nazwy pliku .xlsx. W tym przykładzie użyto właściwości [ServerDocument Constructor (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.Document%2A> , aby wyświetlić liczbę bajtów w dokumencie.
Ten przykład wymaga:
Projekt aplikacji konsoli lub innych projektów nienależących do pakietu Office.
Odwołania do następujących zestawów:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jeśli projekt jest przeznaczony dla .NET Framework 4 lub .NET Framework 4.5).
lub
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (jeśli projekt jest przeznaczony dla programu.NET Framework 3.5).
Imports
(dla języka Visual Basic) lubusing
(w przypadku instrukcji C#) dla instrukcji [ServerDocument Constructor (Byte xref:Microsoft.VisualStudio.Tools.Applications?displayProperty=fullName> i [ServerDocument Constructor (Byte<<xref:Microsoft.VisualStudio.Tools.Runtime?displayProperty=fullName> przestrzeni nazw w górnej części pliku kodu.
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();
}
}
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
Uwagi
Użyj tego konstruktora, aby uzyskać dostęp do buforowanych danych lub informacji manifestu wdrożenia w dokumencie, który jest już w pamięci. Gdy używasz tego konstruktora, dokument jest otwierany z dostępem do odczytu/zapisu.
Parametr fileType
jest używany tylko do określania typu dokumentu przechowywanego w tablicy bajtów. Wartość jest fileType
mapowana na jeden z typów plików obsługiwanych w przypadku dostosowań na poziomie dokumentu. Nie podjęto próby otwarcia pliku. Opcjonalnie możesz przekazać pełną nazwę pliku (na przykład "Workbook1.xlsx"), ale jeśli to zrobisz, zostanie użyte tylko rozszerzenie nazwy pliku. Aby uzyskać więcej informacji na temat obsługiwanych typów plików, zobacz Architektura Document-Level Dostosowania.
Aby uzyskać dostęp do tablicy bajtów dokumentu po wywołaniu tego konstruktora, użyj właściwości [ServerDocument Constructor (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.Document%2A> .
Dotyczy
ServerDocument(Stream, String)
Inicjuje nowe wystąpienie ServerDocument klasy przy użyciu strumienia reprezentującego dokument do załadowania i rozszerzenia nazwy pliku dokumentu.
public:
ServerDocument(System::IO::Stream ^ stream, System::String ^ fileType);
public ServerDocument (System.IO.Stream stream, string fileType);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : System.IO.Stream * string -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (stream As Stream, fileType As String)
Parametry
- stream
- Stream
Strumień reprezentujący dokument do załadowania.
- fileType
- String
Rozszerzenie nazwy pliku dokumentu przechowywanego w parametrze bytes
poprzedzonym kropką (.) — na przykład ".xlsx" lub ".docx".
Wyjątki
Parametr stream
jest lub pusty.-or-Parametr fileType
jest null
null
pusty lub składa się całkowicie z białych znaków.
Parametr stream
ma zerową długość lub jego bieżące położenie znajduje się na końcu strumienia.
Parametr fileType
określa rozszerzenie nazwy pliku, które nie jest obsługiwane przez środowisko uruchomieniowe Visual Studio Tools dla pakietu Office.
Plik określony przez documentPath
program ma dostosowanie, które nie zostało utworzone za pomocą narzędzi Visual Studio 2010 Tools for Office Runtime lub Visual Studio Tools dla systemu Microsoft Office (wersja 3.0 Runtime).
Przykłady
Poniższy przykład kodu używa konstruktora ServerDocument(Stream, String) do utworzenia nowego ServerDocument na podstawie FileStream skoroszytu programu Excel z rozszerzeniem nazwy pliku .xlsx. Następnie kod wyświetla adres URL manifestu wdrożenia dla dostosowania dołączonego do dokumentu.
Ten przykład wymaga:
Projekt aplikacji konsoli lub innych projektów nienależących do pakietu Office.
Odwołania do następujących zestawów:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jeśli projekt jest przeznaczony dla .NET Framework 4 lub .NET Framework 4.5).
lub
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (jeśli projekt jest przeznaczony dla programu.NET Framework 3.5).
Imports
(dla języka Visual Basic) lubusing
(w przypadku języka C#) instrukcje dla Microsoft.VisualStudio.Tools.Applications przestrzeni nazw i Microsoft.VisualStudio.Tools.Applications.Runtime w górnej części pliku kodu.
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();
}
}
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
Uwagi
Użyj tego konstruktora, aby uzyskać dostęp do buforowanych danych lub informacji manifestu wdrożenia w dokumencie, który jest już w pamięci. Gdy używasz tego konstruktora, dokument jest otwierany z dostępem do odczytu/zapisu.
Parametr fileType
jest używany tylko do określania typu dokumentu przechowywanego w tablicy bajtów. Wartość jest fileType
mapowana na jeden z typów plików obsługiwanych w przypadku dostosowań na poziomie dokumentu. Nie podjęto próby otwarcia pliku. Opcjonalnie możesz przekazać pełną nazwę pliku (na przykład "Workbook1.xlsx"), ale jeśli to zrobisz, zostanie użyte tylko rozszerzenie nazwy pliku. Aby uzyskać więcej informacji na temat obsługiwanych typów plików, zobacz Architektura Document-Level Dostosowania.
Aby uzyskać dostęp do tablicy bajtów dokumentu po wywołaniu tego konstruktora, użyj Document właściwości .
Dotyczy
ServerDocument(String, FileAccess)
Inicjuje nowe wystąpienie ServerDocument klasy przy użyciu pełnej ścieżki dokumentu do załadowania i wartości wskazującej dostęp do pliku dla dokumentu.
public:
ServerDocument(System::String ^ documentPath, System::IO::FileAccess access);
public ServerDocument (string documentPath, System.IO.FileAccess access);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : string * System.IO.FileAccess -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (documentPath As String, access As FileAccess)
Parametry
- documentPath
- String
Pełna ścieżka dokumentu do załadowania.
- access
- FileAccess
Wartość wskazująca dostęp do pliku dla dokumentu.
Wyjątki
Parametr documentPath
jest null
pusty lub składa się całkowicie z białych znaków.
Wartość access
to System.IO.FileAccess.Write.
Plik określony przez documentPath
nie istnieje.
Plik określony przez documentPath
parametr nie ma dostosowania, a wartość access
to System.IO.FileAccess.Read.
Plik określony przez documentPath
program ma dostosowanie, które nie zostało utworzone za pomocą narzędzi Visual Studio 2010 Tools for Office Runtime lub Visual Studio Tools dla systemu Microsoft Office (wersja 3.0 Runtime).
Plik określony przez documentPath
ma rozszerzenie nazwy pliku, które nie jest obsługiwane przez środowisko uruchomieniowe Visual Studio Tools dla pakietu Office.
Przykłady
Poniższy przykład kodu używa konstruktora ServerDocument(String, FileAccess) do utworzenia nowego ServerDocument , który ładuje określony dokument z dostępem tylko do odczytu. Następnie kod wyświetla adres URL manifestu wdrożenia dla dostosowania dołączonego do dokumentu.
Ten przykład wymaga:
Projekt aplikacji konsoli lub innych projektów nienależących do pakietu Office.
Odwołania do następujących zestawów:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jeśli projekt jest przeznaczony dla .NET Framework 4 lub .NET Framework 4.5).
lub
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (jeśli projekt jest przeznaczony dla programu.NET Framework 3.5).
Imports
(dla języka Visual Basic) lubusing
(w przypadku języka C#) instrukcje dla Microsoft.VisualStudio.Tools.Applications przestrzeni nazw i Microsoft.VisualStudio.Tools.Applications.Runtime w górnej części pliku kodu.
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();
}
}
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
Uwagi
Użyj tego konstruktora, aby uzyskać dostęp do buforowanych danych lub informacji manifestu wdrożenia w dokumencie, który znajduje się na dysku, jeśli chcesz otworzyć dokument z dostępem tylko do odczytu lub tylko do zapisu. Domyślnie inne ServerDocument konstruktory otwierają dokument z dostępem do odczytu/zapisu.