-2

I am working on an ASP.NET MVC 5 application where the user can upload videos. I've noticed a problem where sometimes the videos are not found because it appears that they have duplicate file extensions.

enter image description here

What is confusing me is inside the debugger I get the correct path... C:\Users\MyUser\Documents\visual studio 2013\Projects\MyStructures\MyStructures\Content\Videos\bbb.mp4 but it is not showing in the content folder in Visual Studio. enter image description here

When I open that folder using File Explorer the file is there. enter image description here

The code that displays the video pulls the filename from the database.

@if (!string.IsNullOrEmpty(post.VideoFileName))
{
    <div>
    <video width="400" controls>
        <source src="~/Content/Videos/@post.VideoFileName" type="video/mp4">
        <source src="~/Content/Videos/@post.VideoFileName" type="video/ogg">
        <source src="~/Content/Videos/@post.VideoFileName" type="video/webm">
        <p>Your browser does not support HTML5 video.</p>
    </video></div>
}

How can I check for and remove these duplicate file extensions using C#?

Jonathan Kittell
  • 7,163
  • 15
  • 50
  • 93
  • 1
    Are you saying the file is called bbb.mp4.mp4? – itsme86 Feb 06 '15 at 19:06
  • @MatthewG I don't know how to change the extension to remove the two .mp4 extensions. I have edited my answer. – Jonathan Kittell Feb 06 '15 at 19:15
  • How are you searching for the videos in code? It might not be because of repeated file extensions. – Mark Cidade Feb 06 '15 at 19:15
  • The solution explorer lets you show files that aren't included in the project and include them. It does not show you all files in those directories by default. The question is, where's the code that illustrates your actual problem? – SimpleVar Feb 06 '15 at 19:21
  • you have explorer set to not show extensions -- change that life will be easier. Then you can actually see what the file name is in the directory. – Hogan Feb 06 '15 at 19:21
  • I still don't understand your meaning with "removing duplicate file extensions". If the file name was accidentally "bbb.mp4.mp4", it would show the file name to be "bbb.mp4" when it doesn't show you the extension in the file explorer. But your file name is "bbb" which leads me to think it's full path is valid and appropriate, as "folders/bbb.mp4" – SimpleVar Feb 06 '15 at 19:23

2 Answers2

5

They don't have duplicate extensions. The first part is the type description registered by the application ("VLC media file (.mp4)"), where the extension in the type is a VLC feature, and the second part shows the actual extension "(.mp4)". Try a JPEG file: "JPEG image (.jpg)", or an unknown type: "BAR File (.bar)".

I think any developer should enable Explorer to display file extensions anyway. Open an Explorer window, click View (or Tools) -> Options, go to the View tab and uncheck "Hide extensions for known types".

You're troubleshooting the wrong issue here.

Files on disk don't show up in Visual Studio's Solution Explorer by default. To include an existing file, select your project or the folder and click the "Show all files" button. There you'll see the file, and you can right-click it and select "Include in project".

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
2

You have several different approaches, but you'll want to look at System.IO namespace. In particular, the following:

  • DirectoryInfo
  • FileInto

The example on the Microsoft Developer Network is quite stellar.

You haven't provided any code, which makes me hesitant to answer mostly since by me doing the task doesn't help teach you.

Greg
  • 11,302
  • 2
  • 48
  • 79