如何在c sharp中获取本地文件位置 [英] how to get local file location in c sharp

查看:133
本文介绍了如何在c sharp中获取本地文件位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

如何在asp.net中使用文件上传器获取文件的本地路径,就像我浏览文件 D:\\wildlife.flv



我想使用文件上传器获取此路径我尝试了很多东西,但它给了我路径,如 D:\\ video application \\wildlife 但是我希望路径如下: D:\\ wildlife 我的应用程序文件夹名称。

实际上我想将路径传递给此命令:

hello,
how to get local path of file using file uploader in asp.net, like i browse file D:\\wildlife.flv

I want to get this path using file uploader i tried many thing but it giving me path like D:\\ video application\\wildlife but i want the path like: D:\\ wildlife with out my application folder name.
actually i want to pass path to this command:

_mhandler.CustomCommand = "-i D:\\WildLife.wmv -vf fade=in:1:400 C:\\ConvertedV.wmv";



谢谢和问候。



lakhan


thanks and regards.

lakhan

推荐答案

我认为这个解决方案可以帮助你......克服你的问题...



Server.MapPath(〜/ Files )返回基于相对于您的应用程序的文件夹的绝对路径。领先的〜/告诉ASP.Net查看你的应用程序的根目录。



使用应用程序之外的文件夹:



I think This Solution Will Help you...to overcome from your problem...

Server.MapPath("~/Files") returns an absolute path based on a folder relative to your application. The leading ~/ tells ASP.Net to look at the root of your application.

To use a folder outside of the application:

 //check to make sure a file is selected
if (FileUpload1.HasFile)
{
    //create the path to save the file to
    string fileName = Path.Combine(@"E:\Project\Folders", FileUpload1.FileName);
    //save the file to our local path
    FileUpload1.SaveAs(fileName);
}



当然,你不会在生产应用程序中硬编码路径,但这应该使用你描述的绝对路径保存文件。 />


关于在保存文件后查找文件(每条评论):




Of course, you wouldn''t hardcode the path in a production application but this should save the file using the absolute path you described.

With regards to locating the file once you have saved it (per comments):

if (FileUpload1.HasFile)
{
    string fileName = Path.Combine(@"E:\Project\Folders", FileUpload1.FileName);
    FileUpload1.SaveAs(fileName);

    FileInfo fileToDownload = new FileInfo( filename ); 

    if (fileToDownload.Exists){ 
        Process.Start(fileToDownload.FullName);
    }
    else { 
        MessageBox("File Not Saved!"); 
        return; 
    }
} 


这篇关于如何在c sharp中获取本地文件位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆