Skip to content

Commit 961c298

Browse files
committed
Timeout in SpreadProcessing providers
1 parent 12c7223 commit 961c298

File tree

8 files changed

+140
-99
lines changed

8 files changed

+140
-99
lines changed

introduction.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ position: 0
3131

3232
* **Support for Variety of File Formats**: The Telerik Document Processing includes 5 libraries for manipulating [Office Open XML](https://en.wikipedia.org/wiki/Office_Open_XML) file formats and PDF documents in your application.
3333

34+
* **Timeout Mechanism** when importing and exporting documents. The **Import** and **Export** methods for all FormatProviders have a mandatory *TimeSpan?* timeout parameter after which the operation will be cancelled.
35+
3436
For more details about the benefits of using Telerik Document Processing, see the [Telerik Document Processing product overview page](https://www.telerik.com/document-processing-libraries).
3537

3638
## Supported Formats

libraries/radspreadprocessing/formats-and-conversion/csv/csvformatprovider.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ __Example 1__ shows how to import a CSV file using a __FileStream__. The code as
3838

3939
using (Stream input = new FileStream(fileName, FileMode.Open))
4040
{
41-
//workbook = formatProvider.Import(input);
42-
//This method is obsolete since Q4 2024.
41+
//workbook = formatProvider.Import(input); //This method is obsolete since Q4 2024.
4342

4443
workbook = formatProvider.Import(input, TimeSpan.FromSeconds(10));
4544
}
@@ -56,19 +55,18 @@ __Example 2__ demonstrates how to export an existing Workbook to a CSV file. The
5655
#### __[C#] Example 2: Export CSV file__
5756

5857
{{region cs-radspreadprocessing-formats-and-conversion-csv-csvformatprovider_1}}
59-
Workbook workbook = new Workbook();
60-
workbook.Worksheets.Add();
58+
Workbook workbook = new Workbook();
59+
workbook.Worksheets.Add();
6160

62-
string fileName = "SampleFile.csv";
63-
CsvFormatProvider formatProvider = new CsvFormatProvider();
61+
string fileName = "SampleFile.csv";
62+
CsvFormatProvider formatProvider = new CsvFormatProvider();
6463

65-
using (Stream output = new FileStream(fileName, FileMode.Create))
66-
{
67-
//formatProvider.Export(workbook, output);
68-
//This method is obsolete since Q4 2024.
64+
using (Stream output = new FileStream(fileName, FileMode.Create))
65+
{
66+
//formatProvider.Export(workbook, output); //This method is obsolete since Q4 2024.
6967

70-
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
71-
}
68+
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
69+
}
7270

7371
{{endregion}}
7472

libraries/radspreadprocessing/formats-and-conversion/general-information.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ __RadSpreadProcessing__'s document model allows you to easily open and save file
2121
* __Txt__(tab delimited): Plain text format, which preserves only the content of the cells in the active worksheet. The format does not save any formatting and keeps only the result values of the cells. These values are delimited via tabs.
2222
* **DataTable**: This allows you to convert the DataTable that is coming form your database to a spreadsheet and vice versa.
2323

24+
>note In **Q4 2024** Telerik Document Processing Libraries introduced timeout mechanism when importing and exporting documents. The new **Import** and **Export** methods for all FormatProviders have a mandatory *TimeSpan?* timeout parameter after which the operation will be cancelled.
25+
2426

2527
## Format providers​
2628

libraries/radspreadprocessing/formats-and-conversion/import-and-export-to-excel-file-formats/xls/xlsformatprovider.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ __Example 1__ shows how to import an XLS file using a FileStream. The code assur
3737
{
3838
throw new FileNotFoundException(String.Format("File {0} was not found!", fileName));
3939
}
40-
40+
4141
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook;
4242
IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Xls.XlsFormatProvider();
43-
43+
4444
using (Stream input = new FileStream(fileName, FileMode.Open))
4545
{
46-
workbook = formatProvider.Import(input);
46+
//workbook = formatProvider.Import(input); //This method is obsolete since Q4 2024.
47+
48+
workbook = formatProvider.Import(input, TimeSpan.FromSeconds(10));
4749
}
50+
4851
{{endregion}}
4952

5053

@@ -60,13 +63,16 @@ __Example 2__ demonstrates how to export an existing Workbook to an XLS file. Th
6063
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
6164
workbook.Worksheets.Add();
6265
string fileName = "SampleFile.xls";
63-
66+
6467
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Xls.XlsFormatProvider();
65-
68+
6669
using (Stream output = new FileStream(fileName, FileMode.Create))
6770
{
68-
formatProvider.Export(workbook, output);
71+
//formatProvider.Export(workbook, output); //This method is obsolete since Q4 2024.
72+
73+
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
6974
}
75+
7076
{{endregion}}
7177

7278

@@ -76,15 +82,18 @@ __Example 2__ demonstrates how to export an existing Workbook to an XLS file. Th
7682

7783
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
7884
workbook.Worksheets.Add();
79-
85+
8086
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Xls.XlsFormatProvider();
81-
87+
8288
byte[] bytes;
8389
using (MemoryStream output = new MemoryStream())
8490
{
85-
formatProvider.Export(workbook, output);
91+
//formatProvider.Export(workbook, output); //This method is obsolete since Q4 2024.
92+
93+
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
8694
bytes = output.ToArray();
8795
}
96+
8897
{{endregion}}
8998

9099

libraries/radspreadprocessing/formats-and-conversion/import-and-export-to-excel-file-formats/xlsm/xlsmformatprovider.md

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,22 @@ __Example 1__ shows how to import an Xlsm file using a FileStream. The code assu
3838
#### __[C#] Example 1: Import Xlsm (Excel Workbook) file__
3939

4040
{{region cs-radspreadprocessing-formats-and-conversion-Xlsm-Xlsmformatprovider_0}}
41-
string fileName = "SampleFile.Xlsm";
42-
if (!File.Exists(fileName))
43-
{
44-
throw new FileNotFoundException(String.Format("File {0} was not found!", fileName));
45-
}
46-
47-
48-
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook;
49-
IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider();
50-
51-
using (Stream input = new FileStream(fileName, FileMode.Open))
52-
{
53-
workbook = formatProvider.Import(input);
54-
}
41+
string fileName = "SampleFile.Xlsm";
42+
if (!File.Exists(fileName))
43+
{
44+
throw new FileNotFoundException(String.Format("File {0} was not found!", fileName));
45+
}
46+
47+
48+
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook;
49+
IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider();
50+
51+
using (Stream input = new FileStream(fileName, FileMode.Open))
52+
{
53+
//workbook = formatProvider.Import(input); //This method is obsolete since Q4 2024.
54+
55+
workbook = formatProvider.Import(input, TimeSpan.FromSeconds(10));
56+
}
5557

5658
{{endregion}}
5759

@@ -64,17 +66,20 @@ __Example 2__ demonstrates how to export an existing Workbook to an Xlsm file. T
6466
#### __[C#] Example 2: Export spreadsheet document to Xlsm (Excel Workbook) file__
6567

6668
{{region cs-radspreadprocessing-formats-and-conversion-Xlsm-Xlsmformatprovider_1}}
67-
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
68-
workbook.Worksheets.Add();
69-
string fileName = "SampleFile.Xlsm";
70-
71-
72-
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider();
73-
74-
using (Stream output = new FileStream(fileName, FileMode.Create))
75-
{
76-
formatProvider.Export(workbook, output);
77-
}
69+
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
70+
workbook.Worksheets.Add();
71+
string fileName = "SampleFile.Xlsm";
72+
73+
74+
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider();
75+
76+
using (Stream output = new FileStream(fileName, FileMode.Create))
77+
{
78+
//formatProvider.Export(workbook, output); //This method is obsolete since Q4 2024.
79+
80+
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
81+
}
82+
7883

7984
{{endregion}}
8085

@@ -85,13 +90,15 @@ __Example 2__ demonstrates how to export an existing Workbook to an Xlsm file. T
8590

8691
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
8792
workbook.Worksheets.Add();
88-
93+
8994
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider();
90-
95+
9196
byte[] bytes;
9297
using (MemoryStream output = new MemoryStream())
9398
{
94-
formatProvider.Export(workbook, output);
99+
//formatProvider.Export(workbook, output); //This method is obsolete since Q4 2024.
100+
101+
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
95102
bytes = output.ToArray();
96103
}
97104

libraries/radspreadprocessing/formats-and-conversion/import-and-export-to-excel-file-formats/xlsx/xlsxformatprovider.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,23 @@ __Example 1__ shows how to import an xlsx file using a FileStream. The code assu
3737
#### __[C#] Example 1: Import XLSX (Excel Workbook) file__
3838

3939
{{region cs-radspreadprocessing-formats-and-conversion-xlsx-xlsxformatprovider_0}}
40-
string fileName = "SampleFile.xlsx";
41-
if (!File.Exists(fileName))
42-
{
43-
throw new FileNotFoundException(String.Format("File {0} was not found!", fileName));
44-
}
45-
46-
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook;
47-
IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
48-
49-
using (Stream input = new FileStream(fileName, FileMode.Open))
50-
{
51-
workbook = formatProvider.Import(input);
52-
}
40+
41+
string fileName = "SampleFile.xlsx";
42+
if (!File.Exists(fileName))
43+
{
44+
throw new FileNotFoundException(String.Format("File {0} was not found!", fileName));
45+
}
46+
47+
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook;
48+
IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
49+
50+
using (Stream input = new FileStream(fileName, FileMode.Open))
51+
{
52+
//workbook = formatProvider.Import(input); //This method is obsolete since Q4 2024.
53+
54+
workbook = formatProvider.Import(input, TimeSpan.FromSeconds(10));
55+
}
56+
5357
{{endregion}}
5458

5559

@@ -62,16 +66,20 @@ __Example 2__ demonstrates how to export an existing Workbook to an xlsx file. T
6266
#### __[C#] Example 2: Export spreadsheet document to XLSX (Excel Workbook) file__
6367

6468
{{region cs-radspreadprocessing-formats-and-conversion-xlsx-xlsxformatprovider_1}}
65-
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
66-
workbook.Worksheets.Add();
67-
string fileName = "SampleFile.xlsx";
68-
69-
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
70-
71-
using (Stream output = new FileStream(fileName, FileMode.Create))
72-
{
73-
formatProvider.Export(workbook, output);
74-
}
69+
70+
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
71+
workbook.Worksheets.Add();
72+
string fileName = "SampleFile.xlsx";
73+
74+
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
75+
76+
using (Stream output = new FileStream(fileName, FileMode.Create))
77+
{
78+
//formatProvider.Export(workbook, output); //This method is obsolete since Q4 2024.
79+
80+
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
81+
}
82+
7583
{{endregion}}
7684

7785

@@ -81,15 +89,17 @@ __Example 2__ demonstrates how to export an existing Workbook to an xlsx file. T
8189

8290
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
8391
workbook.Worksheets.Add();
84-
92+
8593
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
86-
94+
8795
byte[] bytes;
8896
using (MemoryStream output = new MemoryStream())
8997
{
90-
formatProvider.Export(workbook, output);
98+
//formatProvider.Export(workbook, output); //This method is obsolete since Q4 2024.
99+
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
91100
bytes = output.ToArray();
92101
}
102+
93103
{{endregion}}
94104

95105

libraries/radspreadprocessing/formats-and-conversion/pdf/pdfformatprovider.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,25 @@ __Example 1__ shows how to use __PdfFormatProvider__ to export a Workbook to a f
5050
using (Stream output = File.OpenWrite("Sample.pdf"))
5151
{
5252
Workbook workbook = CreateSampleWorkbook(); // The CreateSampleWorkbook() method generates a sample spreadsheet document. Use your Workbook object here.
53-
pdfFormatProvider.Export(workbook, output);
54-
}
55-
{{endregion}}
53+
pdfFormatProvider.Export(workbook, output); //This method is obsolete since Q4 2024.
5654

55+
pdfFormatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
56+
}
5757

58+
{{endregion}}
5859

5960
The result from the export method is a document that can be opened in any application that supports PDF documents.
6061

6162
#### __[C#] Example 2: Export to RadFixedDocument__
6263
{{region cs-radspreadprocessing-formats-and-conversion-pdf-pdfformatprovider_1}}
63-
Workbook workbook = CreateSampleWorkbook();
64-
65-
Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider provider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider();
66-
RadFixedDocument fixedDocument = provider.ExportToFixedDocument(workbook);
64+
65+
Workbook workbook = CreateSampleWorkbook();
66+
67+
Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider provider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider();
68+
//RadFixedDocument fixedDocument = provider.ExportToFixedDocument(workbook); //This method is obsolete since Q4 2024.
69+
70+
RadFixedDocument fixedDocument = provider.ExportToFixedDocument(workbook, TimeSpan.FromSeconds(10));
71+
6772
{{endregion}}
6873

6974
>tip __RadFixedDocument__ is the base class of the __RadPdfProcessing__ library. Additional information on the library and its functionality can be found [here]({%slug radpdfprocessing-overview%}).

libraries/radspreadprocessing/formats-and-conversion/txt/txtformatprovider.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ __Example 1__ shows how to import a txt file using a FileStream. The sample inst
2727
#### __[C#] Example 1: Import TXT file__
2828

2929
{{region cs-radspreadprocessing-formats-and-conversion-txt-txtformatprovider_0}}
30-
Workbook workbook;
31-
IWorkbookFormatProvider formatProvider = new TxtFormatProvider();
32-
33-
using (Stream input = new FileStream(fileName, FileMode.Open))
34-
{
35-
workbook = formatProvider.Import(input);
36-
}
30+
31+
Workbook workbook;
32+
string fileName = "input.txt";
33+
IWorkbookFormatProvider formatProvider = new TxtFormatProvider();
34+
35+
using (Stream input = new FileStream(fileName, FileMode.Open))
36+
{
37+
//workbook = formatProvider.Import(input); //This method is obsolete since Q4 2024.
38+
workbook = formatProvider.Import(input, TimeSpan.FromSeconds(10));
39+
}
40+
3741
{{endregion}}
3842

3943

@@ -46,16 +50,20 @@ __Example 2__ demonstrates how to export an existing Workbook to a TXT file. The
4650
#### __[C#] Example 2: Export TXT file__
4751

4852
{{region cs-radspreadprocessing-formats-and-conversion-txt-txtformatprovider_1}}
49-
Workbook workbook = new Workbook();
50-
workbook.Worksheets.Add();
51-
52-
string fileName = "SampleFile.txt";
53-
IWorkbookFormatProvider formatProvider = new TxtFormatProvider();
54-
55-
using (Stream output = new FileStream(fileName, FileMode.Create))
56-
{
57-
formatProvider.Export(workbook, output);
58-
}
53+
54+
Workbook workbook = new Workbook();
55+
workbook.Worksheets.Add();
56+
57+
string fileName = "SampleFile.txt";
58+
IWorkbookFormatProvider formatProvider = new TxtFormatProvider();
59+
60+
using (Stream output = new FileStream(fileName, FileMode.Create))
61+
{
62+
//formatProvider.Export(workbook, output); //This method is obsolete since Q4 2024.
63+
64+
formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
65+
}
66+
5967
{{endregion}}
6068

6169
## See Also

0 commit comments

Comments
 (0)