namespace name 'Lastfm' could not be found - c#

I am using Visual Studio 2010, and this is my first time using an API. When I try to use the Last.FM API, I get the "type or namespace name 'Lastfm' could not be found..." for lines 10 and 48. I've looked at some other StackOverflow questions on similar topics, but none seemed to apply directly.
I downloaded the lastfm-sharp.dll from http://code.google.com/p/lastfm-sharp/downloads/list and placed it in the projects folder. I then added it as a reference and do not recall doing anything else. I then used the example in http://code.google.com/p/lastfm-sharp/wiki/Examples to write my code.
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lastfm.Services;
namespace MusicOrganize
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DIRECTORY = this.FilePath.Text;
}
private void FilePath_TextChanged(object sender, EventArgs e)
{
DIRECTORY = this.FilePath.Text;
}
//Choose what Folder to work with
private void BrowseBtn_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
this.FilePath.Text = folderBrowserDialog1.SelectedPath;
}
}
//Organize Music in selected Directory
private void OrganizeBtn_Click(object sender, EventArgs e)
{
//Put all tracks into one folder
Music.Consolidate(DIRECTORY);
string API_KEY = "****";
string API_SECRET = "****";
Session session = new Session(API_KEY, API_SECRET);
Music.GetTrackTags();
}
public string DIRECTORY;
}
}
Thanks for any help you can provide.

Get the C# documentation.
You either miss the USING statement on the top with all the others that contains the namespace for the class, OR you forgot to add the project or dll as a reference.

And placed it in the projects folder?
Where you keep your lastfm-sharp.dll.Its not sufficient to put it in a Project folder.Put your dll in bin folder .

Related

How to make VS 2012 program to copy itself to startup folder in C#

I want to make my super simple program to copy itself to the startup folder regardless if the os is w7/w8/w10 what I've done already is change the manifesto privileges with this:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
but I found no help for coding it in C# only in VB.
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WMPLib;
namespace Hello
{
public partial class Form1 : Form
{
WindowsMediaPlayer player = new WindowsMediaPlayer();
public Form1()
{
InitializeComponent();
player.URL = "hello.wav";
}
private void Form1_Load(object sender, EventArgs e)
{
Hide();
ShowInTaskbar = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
string saobshtenie = "kp";
string zaglavie = "zdr";
MessageBox.Show(saobshtenie, zaglavie, MessageBoxButtons.OK);
player.controls.play();
}
}
}

DataGridView not saving to database

I am creating a simple staff directory program, and I am making it so the user can update the directory. However, at current time when adding data into the DataGridView, it does not save to the database. I understand that this.staffTableAdapter.Update(this.dBDataSet1.Staff); is needed, which is in my program as you will see below.
I'm just not sure what I am missing at the moment, and would be greatful if anyone could help me out.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace StaffDirectory
{
public partial class Administration : Form
{
public Administration()
{
InitializeComponent();
}
private void staffBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.staffBindingSource.EndEdit();
this.staffTableAdapter.Update(this.dBDataSet1.Staff);
}
private void Administration_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dBDataSet1.Staff' table. You can move, or remove it, as needed.
this.staffTableAdapter.Fill(this.dBDataSet1.Staff);
}
}
}
You should add try-catch block and analyze/provide us with the exception description (ex.Message):
private void staffBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
try{
this.Validate();
this.staffBindingSource.EndEdit();
this.staffTableAdapter.Update(this.dBDataSet1.Staff);
}
catch(Exception ex) {}
}
Also, add this.dBDataSet1.Staff.AcceptChanges(); (re: https://msdn.microsoft.com/en-us/library/ceab2k93.aspx)
Hope this may help. Best regards,

'TileInterfaceTest.UserControl1.label1 is inacessible due to its protection level'

For my A2 computing project I have decided to program a timetable software piece using C#. I have been trying to program a system in which clicking a panel in Form1 will change the text within label1 which is on UserControl1 which has been placed upon panel 2. At first this seemed like a trivial task but it would seem I was punished for my ignorance. As stated in the title when using the solution I thought would work I was told that label1 is 'inacessible due to its protection level', frankly this has baffled me. Anyway, here's the code. I'm quite new to C# and StackOverflow so please be tolerant of any stupid errors.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TileInterFaceTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void panel1_DoubleClick(object sender, EventArgs e)
{
}
private void panel1_Click(object sender, EventArgs e)
{
UserControl1.label1.Text = "Text";
}
}
}
label1 is a private member in UserControl1, so you can't get to access it outside that class.
possible solutions:
1 . in UserControl1 create public property
public string Title
{
get {return label1.Text; }
set {label1.Text = value; }
}
then in your form set that property
private void panel1_Click(object sender, EventArgs e)
{
UserControl1.Title = "Text";
}
2 . the following code should also work
UserControl1.Controls["label1"].Text = "Text";

How in c# make file.txt when click on button?

This is code for windows forms aplication:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication6 {
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
How to create a file, file.txt, when you click on the button?
You have many methods you can use on File, like File.Create. This simply creates or overwrites a file in the local running folder:
private void button1_Click(object sender, EventArgs e)
{
if (!File.Exists("file.txt"))
{
File.Create("file.txt");
}
}
Use File.WriteAllText Method which creates a new file, write the contents to the file, and then closes the file. If the target file already exists, it is overwritten.
private void button1_Click(object sender, EventArgs e)
{
File.WriteAllText("file.txt","your text ");
}

Fiddler Core C# - converting forms application to a C# command prompt project

I followed a tutorial on the web on how to build a fiddlercore C# application which grabs the post URLs and output them to listbox1.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
delegate void UpdateUI();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Fiddler.FiddlerApplication.AfterSessionComplete += new Fiddler.SessionStateHandler(FiddlerApplication_AfterSessionComplete);
Fiddler.FiddlerApplication.Startup(0, Fiddler.FiddlerCoreStartupFlags.Default);
}
void FiddlerApplication_AfterSessionComplete(Fiddler.Session oSession)
{
listBox1.Invoke(new UpdateUI(() =>
{
listBox1.Items.Add(oSession.url);
}));
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Fiddler.FiddlerApplication.Shutdown();
}
}
}
How can I Covert this application into a command project that just outputs in the command window project?
Inside the FiddlerCore folder that the installer creates, there's a project/folder titled Demo. It is a command-line application that is exactly what you are asking for.

Categories