angular-file-upload扩展,附件展示

将上传好后的附件信息,显示在页面上。类似百度文库效果。(目前只写了excel类型的转发方式。)
首先需要引用的DLL

 

效果图

 


 

核心代码
转换代码
#region 文件转换
/// <summary>
/// 文件转换成swf
/// </summary>
/// <param name="type">上传文件的文件格式</param>
/// <param name="onlyData">唯一标识</param>
/// <param name="pathUp">路径</param>
/// <returns></returns>
public bool uploadSwf(string type, string onlyData, string pathUp)
{
try
{
string fileExtention = type;//上传文件的文件格式
string swfToolPath = ConfigurationManager.AppSettings["swfToolPath"];//工具文件的绝对地址
swfToolPath = HttpContext.Current.Server.MapPath(swfToolPath);//工具文件的物理地址
string uploadPath = ConfigurationManager.AppSettings["uploadPath"]; //上传文件夹的绝对地址
uploadPath = HttpContext.Current.Server.MapPath(uploadPath);//上传文件夹地址的物理地址
string uploadFlieName = onlyData + "." + fileExtention; //保存的上传文件名
string uploadPDFName = onlyData + ".pdf";//保存的pdf文件名
string uploadWSFName = onlyData + ".swf";//保存的swf文件名
string uploadPDFPath = uploadPath + uploadPDFName;
string uploadWSFPath = uploadPath + uploadWSFName;
bool bl = Convert(pathUp, fileExtention, uploadPDFPath);
if (bl)
{
#region PDF文件转换为SWF文件
/*-t: 源文件路径,即待转换的pdf文件路径。
* -s: 设置参数,这里我们设置为 flashversion=9 ,即可以转换为9 的版本
* -o: 输出文件的路径
* */
//文件路径包含到""内防止要转换的过程中,文件夹名字带有空格,导致失败
string cmdStr = " -t \"" + uploadPDFPath + "\" -s flashversion=9 -o \"" + uploadWSFPath + "\"";
bool iss = BaseClass.YcTools.PdfToSwf(swfToolPath, cmdStr);//执行文件转换
#endregion
return true;
}
else
{
// ShowBad();
return false;
}
}
catch
{
// ShowBad();
return false;
}
}
private bool Convert(string uploadFliePath, string fileExtention, string uploadPDFPath)
{
BaseClass.ConvertToPDF c = new BaseClass.ConvertToPDF();
bool bl = false;
switch (fileExtention.ToUpper())
{
case "XLS":
case "XLSX":
bl = c.XLS2PDF(uploadFliePath, uploadPDFPath);
break;
case "PDF":
bl = true;
break;
default:
bl = false;
break;
}
return bl;
}
#endregion
转换调用代码
ConvertToPDF
/// <summary>
/// XLS 2 PDF
/// </summary>
/// <param name="sourcePath">源路径</param>
/// <param name="targetPath">目标路径</param>
/// <returns></returns>
public bool XLS2PDF(string sourcePath, string targetPath)
{
bool result = false;
Microsoft.Office.Interop.Excel.XlFixedFormatType targetType = Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF;
object missing = Type.Missing;
Microsoft.Office.Interop.Excel.ApplicationClass application = null;
Microsoft.Office.Interop.Excel.Workbook workBook = null;
try
{
application = new Microsoft.Office.Interop.Excel.ApplicationClass();
object target = targetPath;
object type = targetType;
workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
workBook.ExportAsFixedFormat(targetType, target, Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
result = true;
}
catch
{
result = false;
}
finally
{
if (workBook != null)
{
workBook.Close(true, missing, missing);
workBook = null;
}
if (application != null)
{
application.Quit();
application = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
}
YcTools
/// <summary> //调用新进程,进行转换PDF到SWF文件转换 </summary>
public static bool PdfToSwf(string toolsPath, string cmdStr)
{
bool iss = false;//判断是否转换成功,默认失败
try
{
using (Process p = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo(toolsPath, cmdStr);
p.StartInfo = psi;
p.Start();
p.WaitForExit();
iss = true;//转换成功
}
}
catch { }
return iss;
}
展示页面代码
HTML
<script src="Plugins/FlexPaper/js/jquery.js" type="text/javascript"></script>
<script src="Plugins/FlexPaper/js/flexpaper_flash.js" type="text/javascript"></script>
<div style="width: 1000px; margin:10px auto;">
<input type="hidden" id="hide_path" runat="server" class="hide_path" />
<a id="viewerPlaceHolder" style="width: 1000px; height: 600px; display: block"></a>
<script type="text/javascript">
var swfPath = $(".hide_path").val();
if (swfPath != "") {
var fp = new FlexPaperViewer(
'Plugins/FlexPaper/FlexPaperViewer', /* 对应FlexPaperViewer.swf文件*/
'viewerPlaceHolder', /*对应于a 标签的id*/
{config: {
SwfFile: escape(swfPath), /*SwfFile: 指示导入的.swf的路径*/
Scale: 0.6,
ZoomTransition: 'easeOut',
ZoomTime: 0.5,
ZoomInterval: 0.2,
FitPageOnLoad: true,
FitWidthOnLoad: false,
PrintEnabled: true,
FullScreenAsMaxWindow: false,
ProgressiveLoading: false,
MinZoomSize: 0.2,
MaxZoomSize: 5,
SearchMatchAll: false,
InitViewMode: 'Portrait',
ViewModeToolsVisible: true,
ZoomToolsVisible: true,
NavToolsVisible: true,
CursorToolsVisible: true,
SearchToolsVisible: true,
localeChain: 'en_US'
}
});
}
</script>
</div>
后台CS
private void GetDataBind()
{
//传递保存文件的唯一日期标识。
string path = Request.QueryString["InfoID"] == null ? "" : Request.QueryString["InfoID"];
hide_path.Value = ConfigurationManager.AppSettings["swfShowPath"]+ path + ".swf";
}

posted @ 2016-09-06 17:10  姑苏画中烟  阅读(260)  评论(0编辑  收藏  举报