導航:首頁 > 文件目錄 > 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本地上傳文件路徑獲取相關的資料

熱點內容
ACT文件名 瀏覽:850
無保頑固qq 瀏覽:572
文件如何上傳郵箱 瀏覽:928
java結算 瀏覽:326
蘋果清楚數據軟體在哪裡 瀏覽:995
ug精洗插洗怎麼編程 瀏覽:927
怎樣分享視頻時長過長文件 瀏覽:115
鏡像文件路徑圖片大全 瀏覽:628
蘋果5s怎麼上微信鎖 瀏覽:105
什麼的網路填 瀏覽:567
查國家文件去哪裡查 瀏覽:722
手機上怎麼發文件 瀏覽:64
數據分析過程6個步驟是哪些 瀏覽:622
baksmali最新版本 瀏覽:666
小米查找手機在哪個文件夾 瀏覽:906
編程進銷存用什麼語言 瀏覽:412
linux下獲取目錄下所有文件名 瀏覽:422
note5怎麼退出應用程序 瀏覽:71
qq個性群網名 瀏覽:224
激盪三十年版本哪個好 瀏覽:950

友情鏈接