var virpath1 = "/upload/video/"; string dirFullPath1 = Server.MapPath(virpath1); var video = VideoHelper.GetProductVideoUrl(dirFullPath1, virpath1, model.video, videoName); public static string GetProductVideoUrl(string dirFullPath, string virpath, byte[] model, string qrCode) { if (model == null) { return ""; } else { if (!Directory.Exists(dirFullPath))//如果文件夹不存在,则先创建文件夹 { Directory.CreateDirectory(dirFullPath); } var fileName = qrCode; dirFullPath = dirFullPath + fileName; if (!File.Exists(dirFullPath)) { SaveToVideo(dirFullPath, model); } var url = WebConfigurationManager.AppSettings["hostUrl"].ToString(); return url + virpath + fileName; } } private static void SaveToVideo(string path, byte[] bytes) { FileStream fs = new FileStream(path, FileMode.CreateNew); fs.Write(bytes, 0, bytes.Length); fs.Close(); }