當前位置:首頁 » 文件管理 » c獲取上傳文件路徑

c獲取上傳文件路徑

發布時間: 2022-07-22 11:30:46

❶ C#怎麼獲得客戶端指定文件的路徑

你的步驟錯了。
你要用fileupload控制項,把客戶端的文件傳到伺服器上來,然後再從伺服器上的硬碟上讀取文件,保存到資料庫里。

客戶端的文件路徑對你來說沒什麼意義。例如

string filepath = server.mappath("\img\xxxx.jpg"); //這樣可以取到伺服器的文件路徑。即便這個xxxx.jpg還不存在也沒關系,server.mappath正式把網站的相對路徑映射成伺服器硬碟的物理路徑。然後,你保存之。
fileupload.saveas(filepath);
之後,你在用你的函數,讀這個文件,存到資料庫里。

❷ 用chrome 谷歌瀏覽器上傳文件, js 獲取路徑, 得到的都是c:\fakepath ,, 請問高手怎麼解決這個問題呢.

工具 -> Internet選項 -> 安全 -> 自定義級別 -> 將本地文件上載至伺服器時包含本地目錄路徑,選中啟用即可

❸ c#如何實現將文件上傳到伺服器求詳細代碼謝了

//文件寫入流
private void ReadFile()
{
Byte[] MesageFile;
string path =@"c:\123.XML";
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
int size = Convert.ToInt32(stream.Length);
MesageFile = new Byte[size];
stream.Read(MesageFile, 0, size);
stream.Close()
string fileName =path.Substring(path.LastIndexOf("\\") + 1, path.Length path.LastIndexOf("\\") - 1);
WriteFile(MesageFile, fileName);
}

//寫入文件
private void WriteFile(Byte[] fileByte,string fileName)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "\\UpLoad\\" + DateTime.Now.ToString("yyyy-MM-dd")+"\\";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string savepath = path + fileName;
FileStream fos = new FileStream(savepath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
fos.Write(MesageFile, 0, MesageFile.Length);
fos.Close();
}

上傳的文件格式不限。

❹ C#中FileUpload控制項獲取的路徑為什麼會是C:\Program Files\Common Files\Microsoft\10.0文件在E盤

明顯是IE的安全限制導致你程序獲取路徑有問題。解決方案如下:

  1. 修改IE設置,在InterNet屬性中將允許文件下載啟用即可。這個方法只能是暫時的,因為不同客戶端的IE配置情況不同。

  2. 頁面採用form提交方式,這個問題我在easyui的框架中碰到並解決。如果你request的話肯定是不行的。

    希望能幫到你,如果說的不對請見諒。

❺ fileupload 獲取選中文件的絕對路徑

fileupload 獲取選中文件的絕對路徑,實現參考如下:
protected void BtnUp_Click(object sender, EventArgs e)
{
if (FileUpload.HasFile)
{
string savePath = Server.MapPath("~/upload/");//指定上傳文件在伺服器上的保存路徑
//檢查伺服器上是否存在這個物理路徑,如果不存在則創建
if (!System.IO.Directory.Exists(savePath))
{
System.IO.Directory.CreateDirectory(savePath);
}
savePath = savePath + "\\" + FileUpload.FileName;
FileUpload.SaveAs(savePath);
LabMsg.Text = string.Format("<a href='upload/{0}'>upload/{0}</a>", FileUpload.FileName);
}
else
{
LabMsg.Text = "沒有選擇文件!";
}
}

❻ Extjs文件上傳時路徑總顯示C: akepath,怎樣在extjs的前台獲取上傳文件的真實路徑啊

在瀏覽器--工具--Internet選項--安全--自定義級別--文件上傳至伺服器時包含本地路徑--啟用

❼ 伺服器的文件路徑地址怎麼獲取

絕對路徑:
絕對路徑是指目錄下的絕對位置,直接到的目標位置。 就是你的主頁上的文件或目錄在硬碟上真正的路徑。
直接登錄伺服器就可以看到絕對路徑文件,打開就可以了。

❽ 在c#中(c/s)如何實現將上傳的文件保存到指定的文件夾

參考一下我寫的上傳的事件,我把保存的路徑配置在web.cofig裡面了,(需要注意的是超過一定的大小4M的話就會發生前台的異常,而且這個異常後台沒辦法捕獲,網上有個傢伙寫的捕獲的異常的方法我試了,根本沒有用):

protected void btnSave_Click(object sender, System.EventArgs e)
{
HttpPostedFile postedFile = fileUploadInput.PostedFile;
String userType = this.ddlUserType.SelectedValue;
if (postedFile!=null)
{
//判斷文件是否小於10Mb
if (postedFile.ContentLength < 10485760)
{
try
{
//上傳文件並指定上傳目錄的路徑
String serverPath = System.Configuration.ConfigurationSettings.AppSettings["ReportPath"];
if(serverPath!=null)
{

String fileFullName = fileUploadInput.PostedFile.FileName;
String fileName = Path.GetFileName(fileFullName);
if(getUserManager().isFileNameExist(fileName))
{
lblMsg.Text = "Upload Failed:File with same name already exists!";
}
else
{
if (!Directory.Exists(serverPath))
{
Directory.CreateDirectory(serverPath);
}
postedFile.SaveAs(serverPath+fileName);
getUserManager().saveFileToDataBase(fileName,userType);

lblMsg.Text = "Upload Successfully!";
}

}
else
{
lblMsg.Text = "Upload Failed: Path not found!";
}

/*
* FileUpLoad1.PostedFile.SaveAs(Server.MapPath("~/Files/")+ FileUpLoad1.FileName);
* 注意->這里為什麼不是:FileUpLoad1.PostedFile.FileName
* 而是:FileUpLoad1.FileName?
* 前者是獲得客戶端完整限定(客戶端完整路徑)名稱
* 後者FileUpLoad1.FileName只獲得文件名.
*/

//當然上傳語句也可以這樣寫(貌似廢話):
//FileUpLoad1.SaveAs(@"D:\"+FileUpLoad1.FileName);

}
catch (Exception ex)
{
lblMsg.Text = "Upload Failed,Exception Occurs:" + ex.Message;
}

}
else
{
lblMsg.Text = "Upload Failed:The size of the file can not exceeded 10MB!";
}
}
else
{
lblMsg.Text = "File not seleced!";
}

}

❾ c#獲取文件路徑後,將文件名賦值在label上,比如路徑是c:/123.txt只要123.txt

你是要上傳文件。然後點擊添加文件後把文件命現實到標簽上吧。然後點擊上傳就把文件傳上去么?
思路:你拿到文件的時候用個變數接收絕對路徑。另外一個變數從後面開始截取到有」/「的地方
同事把第二個變數賦值到標簽,最後上傳就把變數1的地址傳進去就OK了。

❿ C#使用HTML文件中的file文件上傳,用C#代碼接收上傳文件

<formid="form1"method="post"enctype="multipart/form-data"action="test.aspx">
<inputid="File1"type="file"name="File1"/>
<inputid="Submit1"type="submit"value="submit"/>
</form>

c# 代碼 test.aspx.cs後台代碼如下:

usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;


publicpartialclasstest:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
if(Request.Files.Count>0)
{
HttpPostedFilef=Request.Files[0];
f.SaveAs(Server.MapPath("test.dat"));
}
}
}
熱點內容
人類語言編譯器 發布:2025-03-22 16:00:19 瀏覽:175
美團編程 發布:2025-03-22 15:50:54 瀏覽:801
禁止地區訪問 發布:2025-03-22 15:48:44 瀏覽:201
ps必須存儲為副本 發布:2025-03-22 15:43:49 瀏覽:111
mac輸出源碼 發布:2025-03-22 15:24:21 瀏覽:119
伺服器固件版本指的什麼 發布:2025-03-22 15:23:34 瀏覽:620
安卓系統怎麼卸載手機應用 發布:2025-03-22 15:22:36 瀏覽:902
直播源碼安裝教程 發布:2025-03-22 15:22:36 瀏覽:677
上傳共享軟體 發布:2025-03-22 15:16:50 瀏覽:138
安卓車機怎麼連接小愛觸屏音響 發布:2025-03-22 14:58:28 瀏覽:748