ServerDocument المنشئ (array<Byte , String)
تهيئة مثيل جديد من ServerDocumentلفئة استخدام صفيف البايت الذي يمثل مستند المراد تحميله و ملف اسم ملحق التطبيق.
مساحة الاسم: Microsoft.VisualStudio.Tools.Applications
التجميع: Microsoft.VisualStudio.Tools.Applications.ServerDocument (في Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)
بناء الجملة
'إقرار
Public Sub New ( _
bytes As Byte(), _
fileType As String _
)
public ServerDocument(
byte[] bytes,
string fileType
)
المعلمات
- bytes
النوع: array<System.Byte[]
صفيف البايت الذي يمثل مستند إلى يمكن تحميله.
- fileType
النوع: System.String
ملف ملحق المستندات المخزنة في bytesاسم معلمة، مسبوقة بعلامة نقطة (.)— على سبيل المثال، ".xlsx" أو ".docx".
استثناءات
استثناء: | شرط |
---|---|
ArgumentNullException | المعلمة هيbytesأو فارغة nullمرجع خالٍ (لا شيء في Visual Basic) . -أو- fileTypeمعلمة هو nullمرجع خالٍ (لا شيء في Visual Basic)أو فارغة أو consهوts من أحرف المسافات البيضاء. |
UnknownCustomizationFileException | fileTypeملف ملحق اسم التي تعين معلمة هو غير معتمد من قبل Visual Studio Tools لوقت تشغيل Office. |
DocumentCustomizedWithPreviousRuntimeException | ملف المحدد مع documentPathله تخصيص التي لم يتم تاريخ الإنشاء مع Visual Studio Tools لـ Office Runtimeأو أدوات Visual Studio لنظام Microsoft المكتب 2010 Suite (الإصدار 3.0 وقت التشغيل). |
ملاحظات
استخدم هذا الدالة الإنشائية الوصول بيانات أو نشرها بيان المعلومات المخزنة مؤقتاً في مستند موجود بالفعل في ذاكرة. عند استخدام هذا الدالة الإنشائية، يتم فتح مستند مع وصول القراءه/الكتابه.
fileTypeمعلمة هو يستخدم فقط لتحديد النوع مستند الذي هو المخزنة في صفيف البايت. الالقيمة fileTypeتم تعيينه إلى إحدى ملف الأنواع المعتمدة للمستند المستوى التخصيصات. يتم إجراء أية محاولة لفتح ملف. يمكنك تمرير في اسم ملف بكامل بشكل اختياري (ل مثال، "Workbook1.xlsx")، ولكن في حالة القيام بذلك، يتم استخدام ملحق اسم الملف فقط. لمزيد من المعلومات حول أنواع الملفات المدعمة، راجع هندسة تخصيصات مستوى المستند.
للوصول إلى صفيفة بايت للمستند بعد استدعاء الدالة الإنشائية هذا، استخدم Documentخاصية.
أمثلة
يستخدم المثال التالي رمز ServerDocument(array<Byte[], String)construcإلىr إلى إنشاء جديد ServerDocumentمن صفيفة البايت التي تحتوي على مصنف Excel باستخدام.xlsx ملف اسم ملحق. يستخدم المثال ثم Documentخاصية لعرض عدد وحدات البايت الموجودة في مستند.
يتطلب هذا المثال:
مشروع تطبيقات وحدة تحكم أو بعض المشاريع بخلاف المكتب الأخرى.
مراجع إلى تجميعات التالية:
Microsoft.VisualStudio.أدوات.Applications.ServerDocument.dll و Microsoft.VisualStudio.أدوات.Applications.وقت التشغيل.dll (إذا كان مشروع تستهدف .NET Framework 4).
أو
Microsoft.VisualStudio.أدوات.Applications.ServerDocument.v10.0.dll و Microsoft.VisualStudio.أدوات.Applications.وقت التشغيل.v9.0.dll (إذا كان مشروع تستهدف 3.5 إطار عمل.NET).
Imports (for Visual Basic) or using (for C#) statements for Microsoft.VisualStudio.Tools.Applications and Microsoft.VisualStudio.Tools.Applications.Runtime namespaces at the top of your code file.
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.
- الثقة الكاملة للمتصل الفوري. يتعذر استخدام هذا العضو بواسطة التعليمات البرمجية الموثوق بها جزئيًا. لمزيد من المعلومات، راجع باستخدام مكتبات من تعليمات برمجية موثوق بها جزئي.