用C#上传文件 [英] Upload Documents in C#

查看:76
本文介绍了用C#上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C#上传一份文件。

我使用了Fallowing代码:



  if ((FileUpload1.PostedFile!=  null )&&& FileUpload1.PostedFile.ContentLength >   0 ))
{

string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string SaveLocation = Server.MapPath( 上传)+ // + fn;
try
{
FileUpload1.PostedFile.SaveAs(SaveLocation);
Label1.Text = 文件已成功上传;
}

catch (例外情况)
{

}
最后
{
}





它有效在视觉工作室2005中很好

当我部署它时不上传文件..

plz help。

解决方案

  if ((docUpload.PostedFile!=  null  )&&(docUpload.PostedFile.ContentLength >   0 ))
{

string fn = System.IO.Path.GetFileName(docUpload.PostedFile.FileName);
string saveLocation = Server.MapPath( 〜/上传/)+ fn;
尝试
{
docUpload.PostedFile.SaveAs(saveLocation);
Label1.Text = 文件已成功上传;
}

catch (例外情况)
{

}


I want upload a Document in C#
I used the Fallowing code:

if ((FileUpload1.PostedFile != null) &&FileUpload1.PostedFile.ContentLength > 0))
        {

            string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
            string SaveLocation = Server.MapPath("Uploads") +//+ fn;
            try
            {
                FileUpload1.PostedFile.SaveAs(SaveLocation);
                Label1.Text = "File Uploaded Sucessfully";
            }

            catch (Exception ex)
            {

            }
            finally
            {
            }



it works fine in the visual studio 2005
when i deployed the same its not uploading the the document..
plz help.

解决方案

if ((docUpload.PostedFile != null) && (docUpload.PostedFile.ContentLength > 0))
            {

                string fn = System.IO.Path.GetFileName(docUpload.PostedFile.FileName);
                string saveLocation = Server.MapPath("~/Uploads/") + fn;
                try
                {
                    docUpload.PostedFile.SaveAs(saveLocation);
                    Label1.Text = "File Uploaded Sucessfully";
                }

                catch (Exception ex)
                {

                }


这篇关于用C#上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆