| |
 |
Loading and converting a VSD/VDX/VSS/VSX diagram file - Aspose.Diagram for .NET
|
 |
Please browse a valid VSD, VDX, VSS or VSX diagram file and press any
button to check the output.
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<%@ Page Language="C#" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="LoadDiagram.aspx.cs" Inherits="Aspose.Diagram.Demos.LoadDiagram" Title="Aspose.Diagram Demos" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table width="90%" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td height="41" valign="top">
<img src="/Common/images/heading_lft.jpg" width="19" height="41" /></td>
<td width="100%" class="demos-heading-bg">
<h2 class="demos-heading-bg">
Loading and converting a VSD/VDX/VSS/VSX diagram file - Aspose.Diagram for .NET</h2>
</td>
<td valign="top">
<img src="/Common/images/heading_rt.jpg" width="19" height="41" /></td>
</tr>
</table>
Please browse a valid VSD, VDX, VSS or VSX diagram file and press any
button to check the output. <br />
<br />
<br />
<br />
<table>
<tr>
<td style="width: 400px">
<asp:FileUpload ID="FileUpload1" runat="server" /></td>
</tr>
<tr>
<td style="width: 100px">
<table>
<tr>
<td style="width: 100px">
<asp:Button ID="btnSaveAsVDX" runat="server" Text="Save as VDX" OnClick="btnSaveAsVDX_Click" /></td>
<td style="width: 100px"><asp:Button ID="btnSaveAsVSX" runat="server" Text="Save as VSX" OnClick="btnSaveAsVSX_Click" /></td>
<td style="width: 100px"><asp:Button ID="btnPDF" runat="server" Text="Render to PDF" OnClick="btnPDF_Click" /></td>
<td style="width: 100px">
<asp:Button ID="btnImage" runat="server" Text="Render to Image" OnClick="btnImage_Click" /></td>
<td style="width: 100px">
<asp:Button ID="btnChangeProperties" runat="server" Text="Update Document Properties" OnClick="btnChangeProperties_Click" /></td>
<td style="width: 100px">
</td>
</tr>
</table>
</td>
</tr>
</table>
<%=Session["outMessage"] %>
<% Session["outMessage"] = ""; %>
</asp:Content>
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Aspose.Diagram;
using System.IO;
namespace Aspose.Diagram.Demos
{
public partial class LoadDiagram : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSaveAsVDX_Click(object sender, EventArgs e)
{
/********** VSD/VDX/VSS/VSX File Upload block [Starts]****************/
///The file name to be read
string strFile = "";
///Upload file to server
if (this.FileUpload1.HasFile)
{
if (this.FileUpload1.FileName.EndsWith(".vsd") || this.FileUpload1.FileName.EndsWith(".vdx")
|| this.FileUpload1.FileName.EndsWith(".vss") || this.FileUpload1.FileName.EndsWith(".vsx"))
{
strFile = this.FileUpload1.FileName;
this.FileUpload1.PostedFile.SaveAs(MapPath(this.FileUpload1.FileName));
}
else
{
///Write html message and exit
Session["outMessage"] = "<h3>Invalid file</h3>";
return;
}
}
else
{
//////Write html message and exit
Session["outMessage"] = "<h3>No diagram file</h3>";
return;
}
/********** File Upload block [Ends]****************/
//Save the uploaded file as VDX
Diagram diagram = new Diagram(Server.MapPath(strFile));
File.Delete(Server.MapPath(strFile));
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.ContentType = "application/vnd.ms-visio";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vdx");
this.Response.Flush();
System.IO.Stream vdxStream = this.Response.OutputStream;
diagram.Save(vdxStream, SaveFileFormat.VDX);
this.Response.End();
}
protected void btnChangeProperties_Click(object sender, EventArgs e)
{
/********** VSD/VDX/VSS/VSX File Upload block [Starts]****************/
///The file name to be read
string strFile = "";
///Upload file to server
if (this.FileUpload1.HasFile)
{
if (this.FileUpload1.FileName.EndsWith(".vsd") || this.FileUpload1.FileName.EndsWith(".vdx")
|| this.FileUpload1.FileName.EndsWith(".vss") || this.FileUpload1.FileName.EndsWith(".vsx"))
{
strFile = this.FileUpload1.FileName;
this.FileUpload1.PostedFile.SaveAs(MapPath(this.FileUpload1.FileName));
}
else
{
///Write html message and exit
Session["outMessage"] = "<h3>Invalid file</h3>";
return;
}
}
else
{
//////Write html message and exit
Session["outMessage"] = "<h3>No diagram file</h3>";
return;
}
/********** File Upload block [Ends]****************/
Diagram diagram = new Diagram(Server.MapPath(strFile));
Session["Diagram"] = diagram;
File.Delete(Server.MapPath(strFile));
Server.Transfer("UpdateDocumentInformation.aspx");
}
protected void btnSaveAsVSX_Click(object sender, EventArgs e)
{
/********** VSD/VDX/VSS/VSX File Upload block [Starts]****************/
///The file name to be read
string strFile = "";
///Upload file to server
if (this.FileUpload1.HasFile)
{
if (this.FileUpload1.FileName.EndsWith(".vsd") || this.FileUpload1.FileName.EndsWith(".vdx")
|| this.FileUpload1.FileName.EndsWith(".vss") || this.FileUpload1.FileName.EndsWith(".vsx"))
{
strFile = this.FileUpload1.FileName;
this.FileUpload1.PostedFile.SaveAs(MapPath(this.FileUpload1.FileName));
}
else
{
///Write html message and exit
Session["outMessage"] = "<h3>Invalid file</h3>";
return;
}
}
else
{
//////Write html message and exit
Session["outMessage"] = "<h3>No diagram file</h3>";
return;
}
/********** File Upload block [Ends]****************/
//Save the uploaded file as VSX
Diagram diagram = new Diagram(Server.MapPath(strFile));
File.Delete(Server.MapPath(strFile));
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.ContentType = "application/vnd.ms-visio";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vsx");
this.Response.Flush();
System.IO.Stream vsxStream = this.Response.OutputStream;
diagram.Save(vsxStream, SaveFileFormat.VSX);
this.Response.End();
}
protected void btnPDF_Click(object sender, EventArgs e)
{
/********** VSD/VDX/VSS/VSX File Upload block [Starts]****************/
///The file name to be read
string strFile = "";
///Upload file to server
if (this.FileUpload1.HasFile)
{
if (this.FileUpload1.FileName.EndsWith(".vsd") || this.FileUpload1.FileName.EndsWith(".vdx")
|| this.FileUpload1.FileName.EndsWith(".vss") || this.FileUpload1.FileName.EndsWith(".vsx"))
{
strFile = this.FileUpload1.FileName;
this.FileUpload1.PostedFile.SaveAs(MapPath(this.FileUpload1.FileName));
}
else
{
///Write html message and exit
Session["outMessage"] = "<h3>Invalid file</h3>";
return;
}
}
else
{
//////Write html message and exit
Session["outMessage"] = "<h3>No diagram file</h3>";
return;
}
/********** File Upload block [Ends]****************/
//Save the uploaded file as PDF
Diagram diagram = new Diagram(Server.MapPath(strFile));
File.Delete(Server.MapPath(strFile));
MemoryStream pdfStream = new MemoryStream();
diagram.Save(pdfStream, SaveFileFormat.PDF);
byte[] pdfContent = pdfStream.GetBuffer();
pdfStream.Close();
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.Charset = "UTF-8";
this.Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Response.ContentType = "application/pdf";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.pdf");
this.Response.BinaryWrite(pdfContent);
this.Response.End();
}
protected void btnImage_Click(object sender, EventArgs e)
{
/********** VSD/VDX/VSS/VSX File Upload block [Starts]****************/
///The file name to be read
string strFile = "";
///Upload file to server
if (this.FileUpload1.HasFile)
{
if (this.FileUpload1.FileName.EndsWith(".vsd") || this.FileUpload1.FileName.EndsWith(".vdx")
|| this.FileUpload1.FileName.EndsWith(".vss") || this.FileUpload1.FileName.EndsWith(".vsx"))
{
strFile = this.FileUpload1.FileName;
this.FileUpload1.PostedFile.SaveAs(MapPath(this.FileUpload1.FileName));
}
else
{
///Write html message and exit
Session["outMessage"] = "<h3>Invalid file</h3>";
return;
}
}
else
{
//////Write html message and exit
Session["outMessage"] = "<h3>No diagram file</h3>";
return;
}
/********** File Upload block [Ends]****************/
//Save the uploaded file as PDF
Diagram diagram = new Diagram(Server.MapPath(strFile));
File.Delete(Server.MapPath(strFile));
MemoryStream imageStream = new MemoryStream();
diagram.Save(imageStream, SaveFileFormat.PNG);
byte[] imageContent = imageStream.GetBuffer();
imageStream.Close();
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.Charset = "UTF-8";
this.Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Response.ContentType = "image/png";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.png");
this.Response.BinaryWrite(imageContent);
this.Response.End();
}
}
}
|
|
|
|