|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
I need to access my gmail contacts to upgrade an Access database. A program in C # manages this basis. I checked on the Internet and appeared several ways, but none worked. I found a video that the speaker creates the code step by step and in the end he managed to access the gmail contacts.
I typed the code and is giving an error in word in of code:
foreach (Contact contato in f.Entries)
The following code:
using System;
using System.Data;
using Google.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
namespace ContatosGmail
{
public partial class Default : System.Web.UI.Page
{
protected void btnObter_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.Tables.Add("GmailContacts");
ds.Tables[0].Columns.Add("EmailId");
RequestSettings rs = new RequestSettings("Taveira", txtUsername.Text, txtPassword.Text);
rs.AutoPaging = true;
ContactsRequest cr = new ContactsRequest(rs);
Feed<Contact> f = cr.GetContacts();
foreach (Contact contato in f.Entries)
{
foreach (EMail email in contato.Emails)
{
DataRow row = ds.Tables[0].NewRow();
row["EmailId"] = email.Address.ToString();
ds.Tables[0].Rows.Add(row);
}
}
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
lblStatus.Text = "Toal de contatos para " + txtUsername.Text + ": " + ds.Tables[0].Rows.Count.ToString();
}
}
}
I am in urgent need of this solution.
Using Visual Studio Professional 15 and Windows 10.
Thank you.
|
|
|
|
|
Most likely no one here is going to debug this code for you, or provide you with a "fixed" version.
It is your task to analyze the code, single-step through it and observe the specific error(s). Then, ask specific questions here, giving a clear description of the error message(s). And, unless you understand the code, how will you maintain it in the future when Google changes their API's, or some change in whatever occurs ?
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
check for "Contact" . It should be in blue color. Try to navigate.
|
|
|
|
|
When you get an error in your code and post a question about it, it would be helpful if you actually said what the error was. I'm going to go out on a limb and suggest that the exception you see on your first foreach line is that you have an "Object reference not set to an instance of an object" exception. You will see this if the call that is responsible for creating the object (i.e., your call to GetContacts) returns a null value. To be honest, this sounds to me like your RequestSettings are inaccurate or you have something like a Firewall preventing you accessing Google from your app.
I will add that we consider it rude to put "urgent" in a question. It's only urgent for you; you aren't paying us anything for our time and we're all volunteers so it's at our discretion when we answer your question.
This space for rent
|
|
|
|
|
Thanks a lot for the help.
|
|
|
|
|
Been hearing a lot of people having trouble with icons, I decided to updated my article I wrote back in 2004 Access multiple icons in a single icon file[^] with a long needed update.
New version of the library lets you import pictures and create 32bit icons with multiple sizes of the image. Hopefully, this can help people who are having troubles with icons with this replacement for the icon class.
Grab the library and sample app:
GitHub - hazlema/MultiIcon: Display or Convert 32bit icons.[^]
Written in C#, Community 2015
Matthew Hazlett
Fighting the good fight for web usability.
modified 14-Jun-16 19:29pm.
|
|
|
|
|
This forum is for asking questions about, or having technical discussions about, C#.
It's not the place to promote your article. That's the job of the various newsletters, RSS feeds, Twitter feeds, Google+ feeds, and "updated article" lists.
I suggest you remove your message, before trigger-happy members start reporting it as spam.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You might consider posting this on the Lounge; you are, after all, talking about a revised code provided for an article here on CP. There are lots of posts on the Lounge where members talk about their achievements, challenges, current work; quite often these posts do not refer to specific CodeProject resources, or discussions.
However, it appears that the only update (I can see) of the article is that you simply added a message in the comments section announcing it, and linking to the project on GitHub. Unfortunately, it is also correct that some people seem to have have a certain latitude for Lounge post content that others do not (welcome to "human nature"); reaction to your post ? ... who knows ?
It appears to me your code is now in C#, rather than VB.NET; I suggest you edit the article, and at least mention that.
Since, I assume, your new code reflects some new/different ideas, or techniques, compared to a year, or more, ago, one can hope you might revise the article.
You also might notify CP staff of the revision; frequently the e-mail updates from CP members subscribe to include mentions/links to revised articles. I suggest you wait to do that until after you have revised the article text. I am not sure of the exact mechanism for this; perhaps revised articles are selected for mention automatically.
All of this is, of course, imho.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
modified 14-Jun-16 23:40pm.
|
|
|
|
|
I want to create three cars from different directions meeting at the junction
|
|
|
|
|
And how is this relating to C#?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
1) Buy three cars.
2) Get three drivers, and give them each two mobiles.
3) Get them to call each other so they can all hear each other and coordinate activities.
4) Get them to drive at an appropriate speed into the same junction at the same time. I'd recommend videoing the results for YouTube.
(4) May be the hardest part, unless you find really stupid people who don't realize they may well be injured or killed. Alcohol may help here, but would impair coordination as well as being illegal.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I read it a little different, he wanted to build three cars, and then the builders would meet in a junction from different directions.
|
|
|
|
|
Oh, right! That's easy: open a pub on the junction!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
I'm still waiting for the Hammerhead Eagle i-Thrust Coupé GTR.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
And what, exactly, is your question? Please remember that we don't know what you've done or what part you are stuck on without you telling us.
This space for rent
|
|
|
|
|
1. Go to the toy store and buy 3 matchbox cars.
2. Position three lengths of wood in a star like pattern and elevate them 45 degrees on the furthest away from the center.
3. Position the cars at the top of each plank and release them all at the same time.
4. Have a camera handy so you can take a picture when they all crash together.
5. Import that picture to your solution and write the following.
Bitmap CarsCrashingTogether = new Buitmap("CarCrash.jpg");
6. Tada, you now have a Visual Studio application that contains a car crash.
Hope this helps
Matthew Hazlett
Fighting the good fight for web usability.
|
|
|
|
|
Hello,
I am trying to get the list of open windows using C#, here is my code..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace howto_list_desktop_windows
{
static class DesktopWindowsStuff
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsIconic(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "GetWindowText",
ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowText(IntPtr hWnd,
StringBuilder lpWindowText, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "EnumDesktopWindows",
ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool EnumDesktopWindows(IntPtr hDesktop,
EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
private delegate bool EnumDelegate(IntPtr hWnd, int lParam);
private static List<IntPtr> WindowHandles;
private static List<string> WindowTitles;
public static void GetDesktopWindowHandlesAndTitles(
out List<IntPtr> handles, out List<string> titles)
{
WindowHandles = new List<IntPtr>();
WindowTitles = new List<string>();
if (!EnumDesktopWindows(IntPtr.Zero, FilterCallback, IntPtr.Zero))
{
handles = null;
titles = null;
}
else
{
handles = WindowHandles;
titles = WindowTitles;
}
}
private static bool FilterCallback(IntPtr hWnd, int lParam)
{
StringBuilder sb_title = new StringBuilder(1024);
int length = GetWindowText(hWnd, sb_title, sb_title.Capacity);
string title = sb_title.ToString();
if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(title) == false)
{
if (IsIconic(hWnd) == false)
{
{
WindowHandles.Add(hWnd);
WindowTitles.Add(title);
}
}
}
return true;
}
}
}
But this gives some window names which are not open. For example its giving "Windows ShellExperienceHost", which running in task manager. and photos which is under suspended state in task manager.
My intention is simple to list open windows (excluding minimized windows).
How to get rid off these kind of errors ?
Please help me.
|
|
|
|
|
|
can you please edit my code..Sorry I am new to .net and I am not getting how to use EnumWindows
|
|
|
|
|
There are plenty of examples here[^].
This space for rent
|
|
|
|
|
Have you found solution for this issue ? I am facing similar issue.
|
|
|
|
|
I have created a Retry function (using Rx with Rx-main and Rx-xaml packages from NuGet) that uses a timer to Retry the function if an error appears, but if it is not successful within a given timeframe, the presses is aborted.
I use the functiuon like shown below:
textBox.Text = "";
Thread.CurrentThread.Name = "UI Thread";
IScheduler thread1 = new NewThreadScheduler(x => new Thread(x) { Name = "Thread1" });
TimeSpan RetryMaxTime = new TimeSpan(0, 0, 0,0,5);
Observable.Create<int>(o =>
{
Console.WriteLine("Created on " + Thread.CurrentThread.Name);
o.OnNext(1);
o.OnError(new Exception("Something random just happened"));
o.OnCompleted();
return Disposable.Create(() => { });
})
.SubscribeOn(thread1)
.Retry(RetryMaxTime)
.ObserveOnDispatcher()
.Subscribe(
x =>
{
textBox.Text += x.ToString() + Environment.NewLine;
}
, ex => textBox.Text += ex.Message
, () => { textBox.Text += "Completed on " + Thread.CurrentThread.Name; }
);
}
Basically, I used the WeakSubscription code to create the function:
public static class MyExtensions
{
public static IObservable<TItem> Retry<TItem>(this IObservable<TItem> collection,TimeSpan ExceptionTimeout)
{
return Observable.Create<TItem>(obs =>
{
var weakSubscription = new WeakSubscription<TItem>(collection, obs, ExceptionTimeout);
return () =>
{
weakSubscription.Dispose();
};
});
}
public class WeakSubscription<T> : IDisposable, IObserver<T>
{
private readonly WeakReference reference;
private readonly IDisposable subscription;
private Exception LastError;
private bool EndRetry = false;
private bool disposed;
private System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
public WeakSubscription(IObservable<T> observable, IObserver<T> observer, TimeSpan ExceptionTimeout)
{
this.reference = new WeakReference(observer);
var interval = Observable.Interval(ExceptionTimeout);
interval.SubscribeOn(Scheduler.CurrentThread).Subscribe(x =>
EndRetry = true);
this.subscription = observable.Retry()
.Catch<T>(e=>e)
.Subscribe(this);
}
IObservable<T> ExceptionHappened(Exception ex)
{
return null;
}
void IObserver<T>.OnCompleted()
{
var observer = (IObserver<T>)this.reference.Target;
if (observer != null)
observer.OnCompleted();
if (this.EndRetry)
this.Dispose();
}
void IObserver<T>.OnError(Exception error)
{
var observer = (IObserver<T>)this.reference.Target;
LastError = error;
if (observer != null)
observer.OnError(error);
if (this.EndRetry)
this.Dispose();
}
void IObserver<T>.OnNext(T value)
{
var observer = (IObserver<T>)this.reference.Target;
if (observer != null)
observer.OnNext(value);
if (this.EndRetry)
this.Dispose();
}
public void Dispose()
{
if (!this.disposed)
{
this.disposed = true;
this.subscription.Dispose();
}
}
}
}
As you can see, if the operation is unsuccessful after the tries, I'd like to get the Exception that was thrown inside the Retry function. My question is simply, how can I get the error thrown, or is there a better way of doing this altogether?
|
|
|
|
|