当前位置:首页 » 网页前端 » netweb附件
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

netweb附件

发布时间: 2022-08-03 21:05:29

A. C#.NET中如何上传大的附件

修改配置文件的字段

<system.web>

<httpRuntime maxRequestLength="1997151" useFullyQualifiedRedirectUrl="true" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" executionTimeout="300"/>
</system.web>
这个就是 上传文件大小的配置。根据自己的要求改下

B. .net MVC中 在视图中上传的附件图片怎么保存到数据库

如果没有使用ef,其实跟传统的asp.netweb程序应用一个道理呀。用sql抽取出来的数据,table,dataset等还可以使用linq

C. Asp.net 批量上传附件如何实现 谢谢,

FileUpload实现单图片上传,如果想多图片上传,你试试这个:
<tr>
<td align="right" valign="top">
试卷照片:
</td>
<td align="left">
<div id="_container">
<input id="File1" type="file" name="File" runat="server" size="10" />
</div>
</td>
<td align="left" valign="bottom">
<input type="button" value="添加" onclick="addFile()" />
</td>
</tr>
addFile()源码:
//多文件上传,动态生成多个上传控件
function addFile() {
var div = document.createElement("div");
var f = document.createElement("input");
f.setAttribute("type", "file");
f.setAttribute("name", "file");
f.setAttribute("size", "10");
div.appendChild(f);
document.getElementById("_container").appendChild(div);
}

后台页面调用:
#region 上传添加图片的方法
/// <summary>
/// 上传添加图片的方法
/// </summary>
/// <param name="nId">关联id</param>
private static void UploadAndAddPicTures(int nId)
{
LMS.BLL.TRAIN_Pictrue PictrueBLL = new LMS.BLL.TRAIN_Pictrue();
List<LMS.Model.TRAIN_Pictrue> list = new List<LMS.Model.TRAIN_Pictrue>();
//遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
for (int iFile = 0; iFile < files.Count; iFile++)
{
//检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName.ToLower() != "")
{
LMS.Model.TRAIN_Pictrue Pictrue = new LMS.Model.TRAIN_Pictrue();
string scurTypeName = fileName.Substring(fileName.LastIndexOf("."));
//初始化原图物理路径
string sGuid_phy = Guid.NewGuid().ToString();
string sUrl_phy = ConfigurationManager.AppSettings["PhysicsObjectPath"].ToString() + sGuid_phy + scurTypeName;
//初始化缩略图物理路径
string sGuid_web = Guid.NewGuid().ToString();
string sUrl_web = ConfigurationManager.AppSettings["PhysicsObjectPath"].ToString() + sGuid_web + scurTypeName;
postedFile.SaveAs(sUrl_phy);//保存原图
PTImage.ZoomAuto(postedFile, sUrl_web, 100, 100, "", "");//生成缩略图,并保存
//保存原图虚拟路径到数据库
Pictrue.path = ConfigurationManager.AppSettings["WebObjectPath"].ToString() + sGuid_phy + scurTypeName;
//保存缩略图虚拟路径到数据库
Pictrue.shrinkpath = ConfigurationManager.AppSettings["WebObjectPath"].ToString() + sGuid_web + scurTypeName;
Pictrue.parid = nId;
Pictrue.tables = "TRAIN_Hotel_MonthExam";
list.Add(Pictrue);
}
}
PictrueBLL.Add(list);
}
#endregion
希望对你有帮助!

D. .net 新闻发布系统如何实现添加附件

/// <summary>
///上传文件
///</summary>
private void UploadFile(System.Web.UI.HtmlControls.HtmlInputFile AInputfile)
{
if (AInputfile == null)
{
throw new ArgumentNullException();
}

string strUploadFilePath = System.Web.HttpContext.Current.Server.MapPath(".") + "\\你的存储上传文件的文件夹名称\\";
string strModifyFileName = string.Empty;

//创建文件目录
System.IO.DirectoryInfo ADirectoryInfo = new System.IO.DirectoryInfo(strUploadFilePath);
if (!ADirectoryInfo.Exists)
{
ADirectoryInfo.Create();
}

//创建文件完整路径,上传后修改文件名,防止重名。
strModifyFileName = DateTime.Now.ToString("yyyyMMddHHmmssFFF");
int intDotIndex = AInputfile.Value.LastIndexOf(".");
if (intDotIndex > -1)
{
strModifyFileName += AInputfile.Value.Substring(intDotIndex);
}
strModifyFileName = strUploadFilePath + strModifyFileName;

//如果文件已存在,删除文件
if (File.Exists(strModifyFileName))
{
File.Delete(strModifyFileName);
}

// 上传文件
AInputfile.PostedFile.SaveAs(strModifyFileName);
}

调用时把前台aspx页面的 上传控件的 id 传到这个函数的参数,即可。