如何在服务器上保存文件? [英] how can i save file on server?

查看:228
本文介绍了如何在服务器上保存文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,我正在使用uploadfile控件将文件保存在服务器上,这是我正在使用的,但在下面我无法看到服务器上的文件,文件夹仍然为空,您可以指导我吗?

friends i am using uploadfile control to save file on server the which is i am using given below but i am not able to see file on server the folder is still blank can you guide me ??

if (FileUploader.HasFile)
    try
    {
        FileUploader.SaveAs(Server.MapPath("confirm//") +
             FileUploader.FileName);
        Label1.Text = "File name: " +
             FileUploader.PostedFile.FileName + "<br>" +
             FileUploader.PostedFile.ContentLength + " kb<br>" +
             "<br><b>Uploaded Successfully";
    }
    catch (Exception ex)
    {
        Label1.Text = "ERROR: " + ex.Message.ToString();
        Label1.Visible = true;
    }
else
{
    Label1.Text = "You have not specified a file.";
    Label1.Visible = true;
}



[edit] HTML编码摆脱了虚假的结束标记-OriginalGriff [/edit]



[edit]HTML encoded to get rid of spurious closing tags - OriginalGriff[/edit]

推荐答案

检查路径:Server.MapPath根据当前执行的路径返回路径如果未提供合格路径,则为文件位置.您可能要尝试使用〜/confirm/"而不是"confirm//"
Check your path: Server.MapPath returns a path based on the current executing file location if a qualified path is not given. You may want to try "~/confirm/" instead of "confirm//"


您可以使用此代码作为文件名.
You can use this code for file name.
string filename = Path.GetFileName(this.upload.FileName);




也用于服务器上传



and
also use for server upload

upload.SaveAs(Server.MapPath("~/IMEINO/") + filename);



你试试....
一切顺利.



u try it ....
all the best.


这篇关于如何在服务器上保存文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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