|
I don't want my mp3 file accessible to anyone else.
I want to do the following in VisualStudio C#:
1. Right click my project and select -->Add Existing Item. Select my mp3 file.
2. Then in the Properties of my mp3 file change the Build Action to "Embedded Resource".
This now means that my mp3 file is contained inside my exe whenever its built.
But now I don't know how to access this mp3 file to played it. I can access (bitmaps ,gif, wave file) when they are embedded by using the code at the bottom my original post but it does not seem to work when I use it for the mp3 file.
Do you understand what my problem is?? Do you know how to solve it??
and this is the cod :
(for Images)
System.Drawing.Bitmap bitmap1 = resource.Properties.Resources.gif//(or bitmaps);
pictureBox1.Image = resource.Properties.Resources.gif;
(for wav)
SoundPlayer sndplayr = new SoundPlayer(resource.Properties.Resources.wav //(here mp3 not played ));
sndplayr.Play();
who can help me with it please ... i look for it but cant find any help ...
|
|
|
|
|
I want to check while the form load. if the user id is null i want to close the current page and open the login page. I know how to do it in web application. i am new to desktop application. so need help....
|
|
|
|
|
You can take some application label variable for storing USerID at the time of login
|
|
|
|
|
I assume you mean that as your program loads, you need to detect if there is a user id stored on the machine, and if so, treat them as logged in to your program. If not, then load the login screen before they get to see the main form.
Look at program.cs - the Main method is the one which starts your application. In there, check the user id, and if present, continue as normal. If not, bring up your login screen in the same way that the existing code shows the main form.
You can use the app.Config file to store the log-in info: open your projects "Properties" tree node in the Solution Explorer pane, and double click on "settings.settings". You can add a new item there (call it UserId) and retrieve it in your code with "Properties.Settings.Default.mySettingName"
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
|
Hi,
I use a mediaelement control in my wpf project to play videos. When I suddenly pause the video, sometimes a black screen occurs. can any one tell why this happens? It occurs in windows xp while it doesnt show up in windows7. Is this because of some codec problem? Please help...
Thanks,
anand
|
|
|
|
|
need to add GUID for each photos that users had uploaded. I had created a virtual directory in IIS to store the images that users had uploaded.
The coding is
string strImage = "";
if (!File.Exists) (Server.MapPath("D:/Virtual Directory")));
if(FileUpload1.HasFile)
{
strImage = FileUpload1.FileName.ToString();
FileUpload1.SaveAs (Server.MapPath("D:/Virtual Directory/" + FileUpload1.FileName.ToString()));
}
//produces a "blank GUID"
System.Guid blankGuid = new System.Guid();
//produces a new, unique GUID
System.Guid desiredGuid = System.Guid.NewGuid();
Can someone tell me if there is any error in my code and how do I store the pictures in the virtual directory
|
|
|
|
|
It depends on what you are trying to achieve, just upload a random image for display (use a folder per user so the user can overwrite the file and no more id is required) or some more complex use.
I used the id from an identity field (I hate guids) concatenated with the original file name and rather than basing it on if the file existed I based the decision on the data record (I need a record of the file in the database).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Member 8279445 wrote: Can you show an example?
Of what - concatenating the id with the file name - simple string concatenation.
First save the record to the database and get the ID value from the returned value or record,
create the filename string using string.format("{0}{1}",ID,filename) then update the record with the filename string.
There are a number of ways to do this in one transaction in the database if performance is an issue (I have a limited requirement and the extra call to do the update is inconsequential).
Then write the file to the virtual folder or rename the already written file.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
string strImage = "";
if (!File.Exists) (Server.MapPath("D:/Virtual Directory")));
if(FileUpload1.HasFile)
{
strImage = FileUpload1.FileName.ToString();
System.Guid desiredGuid = System.Guid.NewGuid();
FileUpload1.SaveAs (Server.MapPath("D:/Virtual Directory/" + desiredGuid.ToString()));
}
I had something like this but how do I link to the database?
|
|
|
|
|
Ah my mistake - I am so database centric that I assume everyone is.
If you have no requirement to use a database then why do you need it. You need to look at your design requirements. I think you need to look at your design!
What is your goal in uploading images?
Can each user manage their own images (separate folder or prefix with user key)?
Why do you need a GUID in the first place?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I need to use database to store all the images as well as a virtual directory becuase I need to host to the web in the future. I need GUID to uniquly identified a image so no two images will have the same name.
|
|
|
|
|
You don't need a database just because you want to write a web app, they can use the file system too (only within the IIS web root but that is fine).
|
|
|
|
|
|
Uh, just use the System.IO classes like you would in a normal application, and make sure that you're looking in a folder for which you have set up permissions,
|
|
|
|
|
Ok so I was right, you need a record in the database with the filename and the filename needs to unique across multiple users - therefore the GUID (or in my case the numeric ID).
It still comes down to design of your app. Your user needs to be able to decide if he wants to manage an existing image and selects that image from a list/control in which case YOU know the record (you used it to populate the control/list) or upload a new image. Change you viewpoint from the user magicking in an image to managing your data.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm letting the users to upload the image so I need to store it in the virtual directory as well as the database. But there is error with my virtual directory -
'D:/Virtual Directory is a physical path, but a virtual path was expected.
if (@File.Exists(Server.MapPath("D:/Virtual Directory")))
How do I solve this error?
|
|
|
|
|
Greeting Gurus,
More fun with datetime...
The question:
How do you convert the string 20110325 to a datetime with a "yyyy-mm-dd" format?
The goal:
Convert a retrieved string value into a datetime for insertion in to a sql db.
The output:
20110325
System.FormatException: String was not recognized as a valid DateTime (etc.)
The code:
RegistryKey Regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
{
if (Regkey != null)
{
foreach (string subKeyName in Regkey.GetSubKeyNames())
{
RegistryKey subKey = Regkey.OpenSubKey(subKeyName);
string oDate = subKey.GetValue("InstallDate",String.Empty).ToString();
Console.WriteLine(oDate);
DateTime nDate = DateTime.Parse(oDate);
if (!String.IsNullOrEmpty(oDate))
{
Console.WriteLine(nDate.ToShortDateString());
}
subKey.Close();
}
Regkey.Close();
}
}
If I use
DateTime nDate;
nDate = DateTime.TryParse(oDate, out nDate);
I get "Cannot implicitly convert type 'bool' to 'System.DateTime'"
I have also tried the TryParseExact & ParseExact methods and met with failure.
|
|
|
|
|
CCodeNewbie wrote: If I use
DateTime nDate;
nDate = DateTime.TryParse(oDate, out nDate);
I get "Cannot implicitly convert type 'bool' to 'System.DateTime'"
I have also tried the TryParseExact & ParseExact methods and met with
failure.
That's because TryParse returns a bool => true on success and false otherwise.
Use something like
bool b = DateTime.TryParse(oDate, out nDate);
Then you'll have the value in nDate cause it's an out parameter.
All the best,
Dan
|
|
|
|
|
Hi Dan,
I had tried something similar...
DateTime nDate;
bool b = DateTime.TryParse(oDate, out nDate);
{
Console.WriteLine(nDate);
}
but the dates are converted to 01/01/0001.
I am currently thinking I need to format oDate first...
|
|
|
|
|
You may need to use this method[^] which allows you to tell the parser the format of the string.
|
|
|
|
|
Hi Richard,
Same problem. Dates show as 01/01/0001 00:00:00.
RegistryKey subKey = Regkey.OpenSubKey(subKeyName);
string oDate = subKey.GetValue("InstallDate", String.Empty).ToString();
CultureInfo culture;
DateTimeStyles styles;
DateTime nDate;
culture = CultureInfo.InstalledUICulture;
styles = DateTimeStyles.None;
DateTime.TryParse(oDate, culture, styles, out nDate);
Console.WriteLine(nDate);
|
|
|
|
|
I used:
culture = CultureInfo.CurrentCulture;
styles = DateTimeStyles.AssumeLocal;
but I also had to ensure the date was in the format of the local style. If you wish to use a non-standard representation of the date then you need to provide your own implementation of the IFormatProvider[^] interface.
Alternatively, since you know this date is YYYYMMDD you could just split it into its constituent parts and recreate it in the default format for your culture.
|
|
|
|
|
Either use the method as Richard said or make up your own conversion logic,
given that you know that the date in string fromat will always be like "YYYYMMDD" or what have you.
All the best,
Dan
|
|
|
|