以编程方式复制媒体文件 [英] Copying media files programmatically
问题描述
大家好,
我正在开发一个项目,我需要将视频文件上传到服务器.基本上,我已经可以使用WPF在我的项目中获取位置并播放该视频了.
我的想法是要有一个单独的文件夹将文件复制到其中,同时仅将位置路径存储在数据库中,就像我对其他文件(例如图像或xps文档)所做的那样
我尝试用来复制文件的代码是
Hey All,
I am developing a project where I need to upload video files to a server. Basically I already have the means to to get the location and play that video in my project using WPF.
My idea is to have a separate folder to copy the files to, while only storing the location path in my database, as I''ve done with other files (such as images or xps documents)
Code I tried using to copy the file was
OpenFileDialog open = new OpenFileDialog();
open.Title = "Upload Research Video";
open.Filter = "Media Files |*.mpg; *.mpeg; *.m1v; *.mp2; *.mpa; *.mpe; *.avi; *.wmv";
try
{
if (open.ShowDialog().Value)
{
SelectedFileName = open.FileName;
File.Copy(SelectedFileName, @"C:\Users\Cloud\Desktop\" + open.SafeFileName, true);
}
}
catch { }
但这似乎并没有完全起作用,尽管没有引发异常.我不确定为什么,但是它没有出现在我的桌面上.
我应该如何继续复制媒体文件?如果我能指出正确的方向,我将很高兴,因为我尝试过在线搜索,但并没有太大帮助.
在此先谢谢您.:)
But this did not seem to work exactly, although no exceptions were thrown. I''m not exactly sure why but it did not appear on my desktop.
How should I proceed in copying the media file? I would be happy if I can just be pointed in the right direction, as I''ve tried searching online but it hasn''t helped much.
Thanks in advance.:)
推荐答案
需要检查的几件事:
(1)桌面路径正确吗?
(2)该应用程序是否有写权限?
(3)放置一个断点,看看SelectedFileName
和SafeFileName
是什么.
(4)可能会引发异常,但是由于您的catch块为空而被吞下了.
A few things to check:
(1) Is the path to the desktop correct?
(2) Does the app have permissions to write there?
(3) Put a breakpoint and see whatSelectedFileName
andSafeFileName
are.
(4) Maybe an exception is thrown but gets silently swallowed because of your empty catch block.
这篇关于以编程方式复制媒体文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!