如何使用ASP .NET C在数组中使用fileuploader存储浏览的文件名# [英] How to store the filenames browsed using fileuploader in an array using ASP .NET C#
问题描述
在我的应用程序中,我选择使用文件上传器的文件,假设我选择文件,那15个文件包含.mp3,.doc和.docx extensions.I需要将它们分开并将它们存储在一个数组中。我怎么能这样做
if(filuploadmp3.HasFile == true)
{
for(int i = 0; i< Request.Files.Count; i ++)
{
HttpPostedFile PostedFile = Request.Files [i];
if(PostedFile.ContentLength> 0)
{
string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
string extension = System.IO.Path.GetExtension(FileName);
if(extension ==。wav)
{
string [] arr =
}
}
}
}
我的尝试: < br $>
i已经检查过这么多代码,但是所有代码都是从目录中提取出来的,但是我不使用任何目录我只是选择桌面上的文件,点击上传时点击上传我需要分离这些扩展我该怎么做
你可以使用String.Split来分隔文件名的不同部分,或者看看Path.GetFileName Method(String)(System.IO) [ ^ ]。使用其中一个Collection类型来创建所有文件名的列表。
您需要的是 List< string> 请参阅此处的示例: [ dotnetperls
In my application i am choosing the files using file uploader suppose if i choose files those 15 files contains .mp3,.doc and .docx extensions.I need to seperate them and store them in a array.How can i do this
if (filuploadmp3.HasFile == true) { for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFile PostedFile = Request.Files[i]; if (PostedFile.ContentLength > 0) { string FileName = System.IO.Path.GetFileName(PostedFile.FileName); string extension = System.IO.Path.GetExtension(FileName); if (extension == ".wav") { string[] arr = } } } }
What I have tried:
i had checked so many codes but all of them are extracted from directories but i do not use any directories i just choos the files from my desktop and click upload when i click upload i need to seperate these extensions how can i do this
You can use String.Split to separate the different parts of the filename, or see Path.GetFileName Method (String) (System.IO)[^] . Use one of the Collection types to create a list of all the filenames.
What you need is List<string> see the examples here: [dotnetperls]
这篇关于如何使用ASP .NET C在数组中使用fileuploader存储浏览的文件名#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!