void AddFileButton_Click(object sender, EventArgs e) { String addingExt = Path.GetExtension(MediaFileTextBox.Text); //Determine if a file of this type already exists. if (!theTrack.ContainsFileType(addingExt)) { //A file of this type does not already exist, so go ahead and add it. MediaFile mf = new MediaFile(); mf.TrackId = theTrack.TrackId; if (MediaFileTextBox.Text.StartsWith("http")) { mf.FilePath = MediaFileTextBox.Text; } else { mf.FilePath = "~" + MediaFileTextBox.Text; } mf.UserGuid = SiteUtils.GetCurrentSiteUser().UserGuid; MediaFile.Add(mf); RedirectToThisPage(); } else { AddFileErrorLabel.Text = String.Format(MediaPlayerResources.FileTypeAlreadyExistsErrorText, addingExt); } }
void AddTrackButton_Click(object sender, EventArgs e) { if (SelectedFilesListBox.Items.Count > 0) { MediaTrack mt = new MediaTrack(); //Populate the MediaTrack object. mt.PlayerId = thePlayer.PlayerId; mt.TrackType = thePlayer.PlayerType; mt.UserGuid = SiteUtils.GetCurrentSiteUser().UserGuid; mt.Name = TrackNameTextBox.Text; mt.Artist = ArtistTextBox.Text; mt.TrackOrder = TracksGridView.Rows.Count + 1; try { //Add the MediaTrack mt.TrackId = MediaTrack.Add(mt); //Add the MediaFiles foreach (ListItem filePath in SelectedFilesListBox.Items) { MediaFile mf = new MediaFile(); mf.TrackId = mt.TrackId; if (filePath.Text.StartsWith("http")) { mf.FilePath = filePath.Text; } else { mf.FilePath = "~" + filePath.Text; } mf.UserGuid = mt.UserGuid; MediaFile.Add(mf); } RedirectToThisPage(); } catch (Exception ex) { //Perform backout actions of anything already saved //The Forgien key of the MediaFiles table is set up with a Cascading delete, so //the deleting of the MediaTracks will also delete any related MediaFiles. MediaTrack.RemoveForPlayer(thePlayer.PlayerId); //Display error to user AddTrackErrorLabel.Text = ex.Message; } } else { AtLeastOneFileSelectedValidator.IsValid = false; AddTrackErrorLabel.Text = MediaPlayerResources.AtLeastOneFileSelectedValidatorErrorMessage; } }
private void Upload(FileUpload fileUpload, TextBox textBox, CheckBox checkBox) { if (textBox.Text.Trim().Length < 1) { return; } MediaFile _MediaFile = new MediaFile(); _MediaFile.Name = AppUtils.MediaFileName(fileUpload.PostedFile.FileName.ToLower()); _MediaFile.Ext = Path.GetExtension(_MediaFile.Name).Replace(".", ""); _MediaFile.Path = lblMediaPath.Text + _MediaFile.Name; _MediaFile.Size = fileUpload.PostedFile.ContentLength; _MediaFile.UserID = AppUtils.UserID(); _MediaFile.Description = textBox.Text.Trim(); _MediaFile.Tags = ""; try { fileUpload.SaveAs(Server.MapPath(Constant.MEDIA_PATH + _MediaFile.Path)); _MediaFile.Add(); var _NewsMedia = new NewsMedia(); _NewsMedia.NewsID = AppUtils.Request("id"); _NewsMedia.FileID = _MediaFile.FileID; _NewsMedia.Order = 0; _NewsMedia.Add(); if (checkBox.Checked || string.IsNullOrEmpty(imgImageUrl.ImageUrl)) { imgImageUrl.ImageUrl = Constant.MEDIA_PATH + _MediaFile.Path; var _News = new News() { NewsID = AppUtils.Request("id") }; _News = _News.Get(); _News.ImageUrl = imgImageUrl.ImageUrl.Replace(Constant.MEDIA_PATH, ""); _News.Update(); } // Khởi tạo lại form upload ảnh textBox.Text = ""; checkBox.Checked = false; } catch { Message.Alert(Page, "Có lỗi khi upload ảnh, vui lòng báo người quản trị!"); } }
protected void btUpload_Click(object sender, EventArgs e) { if (!AppUtils.CheckPath()) { Message.Alert(Page, "Không tạo được thư mục!"); } if (fuFileUpload.PostedFile == null || fuFileUpload.PostedFile.ContentLength == 0) { return; } MediaFile _MediaFile = new MediaFile(); _MediaFile.Name = AppUtils.MediaFileName(fuFileUpload.PostedFile.FileName.ToLower()); _MediaFile.Ext = Path.GetExtension(_MediaFile.Name).Replace(".", ""); _MediaFile.Path = DateTime.Now.ToString("yyyy/MM/dd/") + _MediaFile.Name; _MediaFile.Size = fuFileUpload.PostedFile.ContentLength; _MediaFile.UserID = AppUtils.UserID(); _MediaFile.Description = txtDescription.Text.Trim(); _MediaFile.Tags = txtTags.Text.Trim(); try { fuFileUpload.SaveAs(Server.MapPath(Constant.MEDIA_PATH + _MediaFile.Path)); _MediaFile.Add(); txtKeyword.Text = ""; BindData(); } catch { Message.Alert(Page, "Có lỗi khi upload file!"); } txtPath.Text = Constant.MEDIA_URL + _MediaFile.Path; imgMediaUpload.ImageUrl = Constant.MEDIA_URL + _MediaFile.Path; Response.Redirect(Constant.ADMIN_PATH + Resources.Url.Gallery); }
protected void btUpload_Click(object sender, EventArgs e) { if (!AppUtils.CheckPath()) { Message.Alert(Page, "Không tạo được thư mục!"); } if (fuFileUpload.PostedFile == null || fuFileUpload.PostedFile.ContentLength == 0) { Message.Alert(Page, "Bạn chưa chọn file!"); return; } MediaFile _MediaFile = new MediaFile(); _MediaFile.Name = AppUtils.MediaFileName(fuFileUpload.PostedFile.FileName.ToLower()); _MediaFile.Ext = Path.GetExtension(_MediaFile.Name).Replace(".", ""); _MediaFile.Path = DateTime.Now.ToString("yyyy/MM/dd/") + _MediaFile.Name; _MediaFile.Size = fuFileUpload.PostedFile.ContentLength; _MediaFile.UserID = AppUtils.UserID(); _MediaFile.Description = txtDescription.Text.Trim(); _MediaFile.Tags = txtTags.Text.Trim(); try { fuFileUpload.SaveAs(Server.MapPath(Constant.MEDIA_PATH + _MediaFile.Path)); _MediaFile.Add(); BindData(); } catch { Message.Alert(Page, "Có lỗi khi upload file!"); } txtPath.Text = Constant.MEDIA_URL + _MediaFile.Path; btSave.Visible = true; btUpload.Visible = false; }
protected void btUpload_Click(object sender, EventArgs e) { if (fuFileUpload.PostedFile == null || fuFileUpload.PostedFile.ContentLength == 0) { Message.Alert(Page, "Bạn chưa chọn file!"); return; } MediaFile _MediaFile = new MediaFile(); _MediaFile.Name = AppUtils.MediaFileName(fuFileUpload.PostedFile.FileName.ToLower()); _MediaFile.Ext = Path.GetExtension(_MediaFile.Name).Replace(".", ""); _MediaFile.Path = GetPath() + _MediaFile.Name; _MediaFile.Size = fuFileUpload.PostedFile.ContentLength; _MediaFile.UserID = AppUtils.UserID(); _MediaFile.Description = txtDescription.Text.Trim(); _MediaFile.Tags = txtTags.Text.Trim(); var _NewsMedia = new NewsMedia(); _NewsMedia.NewsID = AppUtils.Request("id"); _NewsMedia.Order = Convert.ToInt32(txtOrder.Text.Trim()); try { fuFileUpload.SaveAs(Server.MapPath(Constant.MEDIA_PATH + _MediaFile.Path)); _MediaFile.Add(); _NewsMedia.FileID = _MediaFile.FileID; _NewsMedia.Add(); Response.Redirect(Request.Url.ToString()); } catch { Message.Alert(Page, "Có lỗi khi upload file!"); } }
public void InstallContent(Module module, string configInfo) { if (string.IsNullOrEmpty(configInfo)) { return; } SiteSettings siteSettings = new SiteSettings(module.SiteId); SiteUser admin = SiteUser.GetNewestUser(siteSettings); XmlDocument xml = new XmlDocument(); using (StreamReader stream = File.OpenText(HostingEnvironment.MapPath(configInfo))) { xml.LoadXml(stream.ReadToEnd()); } MediaPlayer player = new MediaPlayer(); player.ModuleGuid = module.ModuleGuid; player.ModuleId = module.ModuleId; player.PlayerType = MediaType.Audio; if ((xml.DocumentElement.Attributes["type"] != null) && (xml.DocumentElement.Attributes["type"].Value.Length > 0)) { player.PlayerType = (MediaType)Enum.Parse(typeof(MediaType), xml.DocumentElement.Attributes["type"].Value); } MediaPlayer.Add(player); XmlNode tracksNode = null; foreach (XmlNode n in xml.DocumentElement.ChildNodes) { if (n.Name == "tracks") { tracksNode = n; break; } } if (tracksNode == null) { return; } foreach (XmlNode node in xml.DocumentElement.ChildNodes) { if (node.Name == "moduleSetting") { XmlAttributeCollection settingAttributes = node.Attributes; if ((settingAttributes["settingKey"] != null) && (settingAttributes["settingKey"].Value.Length > 0)) { string key = settingAttributes["settingKey"].Value; string val = string.Empty; if (settingAttributes["settingValue"] != null) { val = settingAttributes["settingValue"].Value; if ((key == "HeaderContent") || (key == "FooterContent")) { val = System.Web.HttpUtility.HtmlDecode(val); } } ModuleSettings.UpdateModuleSetting(module.ModuleGuid, module.ModuleId, key, val); } } } foreach (XmlNode trackNode in tracksNode.ChildNodes) { if (trackNode.Name == "track") { XmlAttributeCollection trackAttrributes = trackNode.Attributes; MediaTrack track = new MediaTrack(); track.PlayerId = player.PlayerId; track.TrackType = player.PlayerType; if ((trackAttrributes["name"] != null) && (trackAttrributes["name"].Value.Length > 0)) { track.Name = trackAttrributes["name"].Value; } if ((trackAttrributes["artist"] != null) && (trackAttrributes["artist"].Value.Length > 0)) { track.Artist = trackAttrributes["artist"].Value; } MediaTrack.Add(track); XmlNode filesNode = null; foreach (XmlNode n in trackNode.ChildNodes) { if (n.Name == "files") { filesNode = n; break; } } if (filesNode == null) { return; } foreach (XmlNode fileNode in filesNode.ChildNodes) { if (fileNode.Name == "file") { MediaFile mediaFile = new MediaFile(); mediaFile.TrackId = track.TrackId; XmlAttributeCollection fileAttrributes = fileNode.Attributes; string targetFormat = string.Empty; string sourcePath = string.Empty; if ((fileAttrributes["targetPathFormat"] != null) && (fileAttrributes["targetPathFormat"].Value.Length > 0)) { targetFormat = fileAttrributes["targetPathFormat"].Value; } if ((fileAttrributes["sourcePath"] != null) && (fileAttrributes["sourcePath"].Value.Length > 0)) { sourcePath = HostingEnvironment.MapPath(fileAttrributes["sourcePath"].Value); } if (targetFormat != string.Empty) { mediaFile.FilePath = string.Format(CultureInfo.InvariantCulture, targetFormat, module.SiteId.ToInvariantString()); string directory = Path.GetDirectoryName(HostingEnvironment.MapPath(mediaFile.FilePath)); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.Copy(sourcePath, HostingEnvironment.MapPath(mediaFile.FilePath)); MediaFile.Add(mediaFile); } else //targetPathFormat is not defined so we don't need to move the file { mediaFile.FilePath = fileAttrributes["sourcePath"].Value; MediaFile.Add(mediaFile); } } } } } }
public ActionResult edit(FormCollection collection) { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get the return url string returnUrl = collection["returnUrl"]; ViewBag.QueryParams = new QueryParams(returnUrl); // Check if the administrator is authorized if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor", "Author" }) == true) { ViewBag.AdminSession = true; } else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true) { ViewBag.AdminSession = true; ViewBag.AdminErrorCode = 1; ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); return View("index"); } else { // Redirect the user to the start page return RedirectToAction("index", "admin_login"); } // Get all the form values Int32 id = Convert.ToInt32(collection["txtId"]); string title = collection["txtTitle"]; string media_type = collection["selectMediaType"]; HttpPostedFileBase media_file_content = Request.Files["uploadMediaFile"]; // Get the default admin language id Int32 adminLanguageId = currentDomain.back_end_language; // Get translated texts KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC"); // Get the media file post MediaFile mediaFilePost = MediaFile.GetOneById(id); bool postExists = true; // Check if the media files exists if (mediaFilePost == null) { // Create an empty media file mediaFilePost = new MediaFile(); postExists = false; } // Update values mediaFilePost.title = title; mediaFilePost.media_type = media_type; // Create a error message string errorMessage = string.Empty; // Check for errors in the campaign if (mediaFilePost.title.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("title"), "100") + "<br/>"; } // Check if there is errors if (errorMessage == string.Empty) { // Check if we should add the media file if (postExists == false) { // Add the media file Int64 insertId = MediaFile.Add(mediaFilePost); mediaFilePost.id = Convert.ToInt32(insertId); } // Update the media file if (media_file_content.ContentLength > 0) { UpdateMediaFile(mediaFilePost, media_file_content); } // Update the media file MediaFile.Update(mediaFilePost); // Redirect the user to the list return Redirect(returnUrl); } else { // Set form values ViewBag.ErrorMessage = errorMessage; ViewBag.TranslatedTexts = tt; ViewBag.MediaFile = mediaFilePost; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("edit"); } } // End of the edit method