使用C#将文档文件和pdf文件保存在asp.net中 [英] save doc file and pdf file in asp.net with c#
本文介绍了使用C#将文档文件和pdf文件保存在asp.net中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想上传文件.和pdf文件到cdn.在执行此操作之前,我必须将文件保存在系统的物理位置.
问题是如何保存文档.我的sysytem.any中的文件可以帮助我吗?
谢谢&关于
Hi
I want to upload doc. and pdf file to cdn . before doing this i have to save file on physical location of my sysytem .
problem is that how to save doc. file in my sysytem.any can help me ?
Thanks & Regards
推荐答案
在页面上放置FileUpload控件,并处理Click事件.
Put an FileUpload Control on your page, and handle the Click event.
/// <summary>
/// Upload the file to the database.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void butUpload_Click(object sender, EventArgs e)
{
StatusLabel.Text = SaveUpload(FileUpload1);
}
/// <summary>
/// Save an upload into the database.
/// </summary>
/// <param name="fl">Control containing the download.</param>
/// <returns>Status as a string</returns>
private string SaveUpload(FileUpload fl)
{
if (fl.HasFile)
{
try
{
int version = 0;
string filename = Path.GetFileName(fl.FileName); // You may want to all an output path spec here.
byte[] filedata = fl.FileBytes;
File.WriteAllBytes(filename, filedata);
return string.Format("{0} uploaded", filename);
}
catch (Exception ex)
{
return "The file could not be uploaded. The following error occured: " + ex.Message;
}
}
return "Please select a file.";
}
您需要使用文件上传控件.
检查这些:
使用ASP.NET上传文件 [ http://msdn.microsoft.com/en-us/library/aa478971.aspx [ ^ ]
希望对您有所帮助:)
You need to use File upload control.
check these:
File Upload with ASP.NET[^]
http://msdn.microsoft.com/en-us/library/aa478971.aspx[^]
hope it helps :)
这篇关于使用C#将文档文件和pdf文件保存在asp.net中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文