當前位置:首頁 » 網頁前端 » 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 傳到這個函數的參數,即可。