想要使用文件上传将aimage保存在文件夹中 [英] want to save aimage in a folder using file upload

查看:111
本文介绍了想要使用文件上传将aimage保存在文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试将图像保存在我的应用程序的文件夹中

使用文件上传....但它无法正常工作



如果我使用FileUpload1.Postedfile.FileName.ToString(),那么它会给出错误



我该如何解决这个问题? 'ImagesUploaded'是我的应用程序中的一个文件夹。



private void StartUpLoad()

{

//获取已发布图像的文件名

string imgName = FileUpload1.FileName.ToString(); ////// LINE 2或//字符串

//imgName=FileUpload1.Postedfile.FileName.ToString()这也不起作用

//什么都不提供imgName

//设置图像路径

string imgPath =ImagesUploaded /+ imgName;

//然后将其保存到文件夹

FileUpload1.SaveAs(Server.MapPath(imgPath));



//得到大小的字节数

int imgSize = FileUpload1.PostedFile.ContentLength;



//在保存之前验证已发布的文件

if(FileUpload1.PostedFile!= null && FileUpload1.PostedFile.FileName!=)

{

if(FileUpload1.PostedFile.ContentLength> 5120)// 5120 KB表示5MB

{

Page.ClientScript.RegisterClientScriptBlock(typeof(Page),Alert,alert(''File is too big''),true);

}

else

{

//保存文件

//调用方法执行数据插入数据库

ExecuteInsert(imgName,imgSize,imgPath);

Response.Write(成功保存!);

}

} < br $>
}





请建议somethng bros

I want to try to save an image in a folder in my application
Using file upload....but it not working

If i use FileUpload1.Postedfile.FileName.ToString() , than it give error

How can i solve this? ‘ImagesUploaded’ is a folder in my application.

private void StartUpLoad()
{
//get the file name of the posted image
string imgName = FileUpload1.FileName.ToString(); //////LINE 2 or //string
//imgName=FileUpload1.Postedfile.FileName.ToString() this also not working
//give nothing in imgName
//sets the image path
string imgPath = "ImagesUploaded/" + imgName;
//then save it to the Folder
FileUpload1.SaveAs(Server.MapPath(imgPath));

//get the size in bytes that
int imgSize = FileUpload1.PostedFile.ContentLength;

//validates the posted file before saving
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
if (FileUpload1.PostedFile.ContentLength > 5120) // 5120 KB means 5MB
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert(''File is too big'')", true);
}
else
{
//save the file
//Call the method to execute Insertion of data to the Database
ExecuteInsert(imgName, imgSize, imgPath);
Response.Write("Save Successfully!");
}
}
}


pls suggest somethng bros

推荐答案

除了FileUpload1.FileName.ToString()之外,我曾经使用过它一次。这个我用过FileUpload1.FileName;



for exmpal



i have used it once same as u except FileUpload1.FileName.ToString(); this i have used FileUpload1.FileName;

for exmpal

string img = Server.MapPath("/WebSiteName/FolderName_where_To_savePhotos/");
        img += FileUpload1.FileName;
        FileUpload1.SaveAs(img);



或尝试




or try

string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                   FileUpload1.PostedFile.SaveAs(Server.MapPath("~/WebSiteName/FolderName_where_To_savePhotos/") + fileName);







u也照顾相同名称的照片....也使用一些逻辑




u also have take care of same name of photos....for that also use some logic


这篇关于想要使用文件上传将aimage保存在文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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