導航:首頁 > 文件目錄 > asp本地上傳文件路徑獲取

asp本地上傳文件路徑獲取

發布時間:2025-03-28 13:46:29

『壹』 ASP中如何讀取文件夾的名字

<%
infopath=request.servervariables("path_info") '得到文件相對路徑
serverpath=server.mappath("要循環的文件夾/文件夾下的文件") '得到文件絕對路徑 這個我沒改。必須的要在循環的文件夾下面建一個文件。並在上面寫上才可以。

set objfso=createobject("scripting.filesystemobject") '實例文件組件
set objfile=objfso.GetFile(serverpath) '讀取文件所在路徑
set objfolder=objfile.parentfolder '根據文件所在路徑得到上級目錄
%>

<%
for each objfoldercount in objfolder.subfolders '循環顯示文件夾

response.write(objfoldercount.name)
next
%>
也可以這樣
serverpath=server.mappath("要循環的文件夾/文件夾下的文件")
split(serverpath,"/")
之取數組的值就可以了,那就是文件夾

『貳』 在asp.net mvc3 中,在controller中使用HttpPostedFileBase file 參數獲取上傳的文件,文件路徑問題

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcTest1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "歡迎使用 ASP.NET MVC!";

return View();
}

//上傳文件的控制項name是file1,也就是<input type="file" name="file1" />
//上傳到Upload文件夾(與Controllers文件夾同級)
[HttpPost]
public ActionResult About()
{
HttpFileCollectionBase files= Request.Files;
HttpPostedFileBase file = files["file1"];//獲取上傳的文件
if (file != null && file.ContentLength > 0)
{
string path = Server.MapPath("~/Upload/");//獲取uplaod文件夾路徑
try
{
file.SaveAs(path + file.FileName);//保存文件
}
catch (Exception e)
{
throw e;
}
}
else
{
//文件為空的處理
}
return View();
}
}
}

這是我的代碼,我試了,可以上傳成功的,當然不能大於4M,因為web.config我沒配置。
我不知道你那是什麼樣的問題,但是像我這樣是沒有問題的。

閱讀全文

與asp本地上傳文件路徑獲取相關的資料

熱點內容
win用戶文件夾特殊 瀏覽:785
華為手機掃描成pdf文件在哪裡 瀏覽:599
蘋果5s使用蓋世小雞手柄操作 瀏覽:553
哪個服裝設計網站好 瀏覽:813
手機軟體找不到文件 瀏覽:386
提現購是哪個app 瀏覽:114
word如何整體縮小 瀏覽:528
中興光纖貓f460埠映射教程 瀏覽:41
怎麼弄迷你世界編程 瀏覽:702
qq發手機里的文件找不到 瀏覽:832
百度雲文件有密碼忘記了怎麼辦 瀏覽:469
掃描文件掃到哪裡了 瀏覽:85
為什麼淘寶app是黑色的 瀏覽:17
如何在cad中把圖形輸出為pdf文件 瀏覽:535
文件夾橫簽 瀏覽:988
extjs5mvc 瀏覽:614
win7如何安裝資料庫 瀏覽:647
informix資料庫倒數卸數 瀏覽:983
華碩p7h55mplus升級 瀏覽:240
servlet調用jsp 瀏覽:481

友情鏈接