protected void btnUpload_Click(object sender, EventArgs e) { if (mp3Upload.HasFile) { string Extention = Path.GetExtension(mp3Upload.FileName).ToLower(); if (Extention != ".mp3") { //not an mp3 file } else { string FileName = Path.GetFileNameWithoutExtension(mp3Upload.FileName).ToLower(); string FinalTitle = FileName.Replace("<", "<").Replace(">", ">").Replace(@"""", "'"); string Title = FinalTitle.ToLower(); // make sure the directory exists if (!Directory.Exists(UserMP3Dir)) { try { Directory.CreateDirectory(UserMP3Dir); } catch (Exception ex) { throw new Exception(UserMP3Dir + ":::" + ex.ToString()); } StreamWriter SWPlayList = File.CreateText(XMLPlayListLocation); SWPlayList.Write(@"<?xml version='1.0' encoding='UTF-8'?><playlist version='1' xmlns = 'http://xspf.org/ns/0/'><trackList></trackList></playlist>"); SWPlayList.Flush(); SWPlayList.Close(); } //try //{ string WebMp3ID = Next2Friends.Misc.UniqueID.NewWebID(); string MP3FileName = WebMp3ID + ".mp3"; String SavePath = UserMP3Dir + MP3FileName; mp3Upload.SaveAs(SavePath); AddToPlayList(WebMp3ID, Title); RestartPlayer = "true"; Next2Friends.Data.MP3Upload mP3Upload = new Next2Friends.Data.MP3Upload(); mP3Upload.WebMP3UploadID = WebMp3ID; mP3Upload.MemberID = member.MemberID; mP3Upload.Title = Title; mP3Upload.Path = MP3FileName; mP3Upload.Save(); //} //catch (Exception ex) //{ //throw ex; //} } } BuildMp3Lister(); }
public static MP3Upload GetMP3UploadByWebMP3UploadID(string WebMP3UploadID) { Database db = DatabaseFactory.CreateDatabase(); DbCommand dbcommand = db.GetStoredProcCommand("HG_GetMP3UploadByWebMP3UploadID"); db.AddInParameter(dbcommand, "WebMP3UploadID", DbType.String, WebMP3UploadID); List <MP3Upload> MP3UploadList = new List <MP3Upload>(); using (IDataReader dr = db.ExecuteReader(dbcommand)) { MP3UploadList = MP3Upload.PopulateObject(dr); } if (MP3UploadList.Count > 0) { return(MP3UploadList[0]); } else { return(null); } }
/// <summary> /// Takes an prepopulated IDataReader and creates an array of MP3Uploads /// </summary> public static List<MP3Upload> PopulateObject(IDataReader dr) { ColumnFieldList list = new ColumnFieldList(dr); List<MP3Upload> arr = new List<MP3Upload>(); MP3Upload obj; while (dr.Read()) { obj = new MP3Upload(); if (list.IsColumnPresent("Mp3UploadID")) { obj._mp3UploadID = (int)dr["Mp3UploadID"]; } if (list.IsColumnPresent("WebMP3UploadID")) { obj._webMP3UploadID = (string)dr["WebMP3UploadID"]; } if (list.IsColumnPresent("MemberID")) { obj._memberID = (int)dr["MemberID"]; } if (list.IsColumnPresent("Title")) { obj._title = (string)dr["Title"]; } if (list.IsColumnPresent("Path")) { obj._path = (string)dr["Path"]; } if (list.IsColumnPresent("UploadedDT")) { obj._uploadedDT = (DateTime)dr["UploadedDT"]; } arr.Add(obj); } dr.Close(); return arr; }
protected void btnUpload_Click(object sender, EventArgs e) { if (mp3Upload.HasFile) { string Extention = Path.GetExtension(mp3Upload.FileName).ToLower(); if (Extention != ".mp3") { //not an mp3 file } else { string FileName = Path.GetFileNameWithoutExtension(mp3Upload.FileName).ToLower(); string FinalTitle = FileName.Replace("<", "<").Replace(">", ">").Replace(@"""", "'"); string Title = FinalTitle.ToLower(); // make sure the directory exists if (!Directory.Exists(UserMP3Dir)) { try { Directory.CreateDirectory(UserMP3Dir); } catch(Exception ex) { throw new Exception(UserMP3Dir+":::"+ex.ToString()); } StreamWriter SWPlayList = File.CreateText(XMLPlayListLocation); SWPlayList.Write(@"<?xml version='1.0' encoding='UTF-8'?><playlist version='1' xmlns = 'http://xspf.org/ns/0/'><trackList></trackList></playlist>"); SWPlayList.Flush(); SWPlayList.Close(); } //try //{ string WebMp3ID = Next2Friends.Misc.UniqueID.NewWebID(); string MP3FileName = WebMp3ID + ".mp3"; String SavePath = UserMP3Dir + MP3FileName; mp3Upload.SaveAs(SavePath); AddToPlayList(WebMp3ID,Title); RestartPlayer = "true"; Next2Friends.Data.MP3Upload mP3Upload = new Next2Friends.Data.MP3Upload(); mP3Upload.WebMP3UploadID = WebMp3ID; mP3Upload.MemberID = member.MemberID; mP3Upload.Title = Title; mP3Upload.Path = MP3FileName; mP3Upload.Save(); //} //catch (Exception ex) //{ //throw ex; //} } } BuildMp3Lister(); }