I am not sure which assembly is the correct one to use for Windows Phone. The below Url shows an example of using LiveSDK.
http://nikovrdoljak.wordpress.com/2011/09/15/backup-your-windows-phone-isolated-storage-data-to-skydrive-using-live-connect-api/
I have added Microsoft.Live and Microsoft.Live.Control for the References
Code:
client.Session.Status != LiveConnectSessionStatus.Connected
Error:
'Microsoft.Live.LiveConnectSession' does not contain a definition for 'Status'
and no extension method 'Status' accepting a first argument of type 'Microsoft.Live.LiveConnectSession'
could be found (are you missing a using directive or an assembly reference?)
Code:
private LiveConnectClient client;
private void UploadPhoto_Click(object sender, EventArgs e)
{
if (client == null || client.Session == null || client.Session.Status != LiveConnectSessionStatus.Connected)
{
MessageBox.Show("You must sign in first.");
}
else
{
client.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(GetFolderProperties_Completed);
// If you put photo to folder it becomes album.
client.GetAsync("me/skydrive/files?filter=folders,albums");
}
}
So it's fairly obvious the LiveConnectSession doesn't have the Status property. Why do you keep thinking it has it then?
In the example code he's using the Status property of the LiveConnectSessionChangedEventArgs class, not the LiveConnectSession.
A recommendation for re-reading the basics seems in order here.
Live SDk contain the SignIn Button and LiveConnet DLL. To connect to SKyDrive, it is required to use SignIn Button to sign in. Once it is connected, you can use the return session to create a LiveConnectClient.It is good practise to check if the session is still alive before doing any tasks on the SkyDrive.
Related
This question already has an answer here:
UWP app: FileOpenPicker PickSingleFileAsync() can't await
(1 answer)
Closed 5 years ago.
I am building an UWP app (C#) and on click of button, I want to verify input.
If verification fails, I want to display a message saying that there is wrong input.
this is my function which should handle this:
private async void AddContact_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
DBHelper db = new DBHelper();
if(i_name.Text != "" && i_phone.Text != "") {
db.insertPerson(new Person(i_name.Text, i_phone.Text));
Frame.Navigate(typeof(MainPage));
} else {
ContentDialog msg = new ContentDialog() {
Title = "Empty input!",
Content = "Please fill both fields!",
CloseButtonText = "OK"
};
await msg.ShowAsync();
}
}
However, when the last part (await msg.showAsync() ) is typed it stays underlined in red (in VS). The builder reads the following error:
Error CS4036 'IAsyncOperation' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation' could be found (are you missing a using directive for 'System'?) testniStudioApp d:...\SecondPage.xaml.cs 43 Active
Now i tried to assign this call to variable (as I saw that someone solved similiar problem that way), but it still didn't worked.
Then I tried clearing NuGet cache and rebuilding project as stated here, but none of those solutions worked.
I have a hard time understanding what it wants from me.
Every single tutorial on how to display message was written in more or less the same manner, so I can't understand what can be wrong.
using System; was mising.
Thanks to comments for answer
I am a complete noob when it comes to developing webparts for SharePoint 2010. I have created a webpart that has button on it. When that button is clicked, I would like it to redirect the user to another page. That would seem like an easy operation to do but I have run into roadblocks.
In my MyWebPart.ascx.cs file, I have the following bit of code:
protected void Button_Click(object sender, EventArgs e)
{
// Get the values the user inputted
try
{
String category = SearchBySelector.SelectedValue;
String keyword = SearchField.Text;
SPWeb root = SPContext.Current.RootWeb.Url;
String url = root + "/path/to/site.aspx?category=" + category + "&keyword=" + keyword;
SPUtility.Redirect(url);
}
catch (Exception ex)
{
StatusLabel.ForeColor = "#FF0000";
StatusLabel.Text = "Exception encountered." + ex.Message;
}
}
The problem I am having is that SPContext (and SPUtility) is not being recognized in this context. How do I fix this? I assume I need some sort of include somewhere? I am not a C# expert either which is probably evident by my code.
Any help would be appreciated.
You'll need the fully qualified namespaces for both SPContext and SPUtility, which are Microsoft.SharePoint.SPContext and Microsoft.SharePoint.Utilities.SPUtility respectively.
You can either use those fully qualified class names in your code, or tack two using statements onto the top of your code file:
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
If Visual Studio still barks at you about not recognizing these types or namespaces, you'll want to be sure the Microsoft.SharePoint assembly is added to the references in your project. You can add references from the Solution Explorer window in Visual Studio.
I have a usb connected MSR reader and i am trying to get it by using the sample codes proveded in here. This works fine but the problem is when i add the same code to my app it doesn't work. GetDefaultAsync returns null.
private static MagneticStripeReader _reader = null;
public static async void StartRead()
{
if (await CreateDefaultMagneticStripeReaderObject())
{
....
}
}
private static async Task<bool> CreateDefaultMagneticStripeReaderObject()
{
if (_reader == null)
{
_reader = await MagneticStripeReader.GetDefaultAsync();
if (_reader == null)
return false;
}
return true;
}
My code is like above, very similer to sample but it doesnt work. Also i've added the device capability of pointOfService. So that is not the case.
I was in the exact same situation and I spent the last 5 hours, finally I know what was going on. You are missing a capability in the Package.appxmanifest
'pointOfService' is the capability you want to include. This capability does not show in the UI and therefore I could not find any difference between my broken project and Microsoft's sample project. You can not add that capability using the UI. You have to manually add it by modifying the XML file.
The sample project by Microsoft have it too
https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/MagneticStripeReader/cs/Package.appxmanifest#L53
Make sure the card reader is in HID mode and not Keyboard emulation mode. That was one of my problems.
To do this is really wonky. MagTek has a ActiveX control on their website to assist us... because ActiveX is awful, you can only use it with InternetExplorer (it won't even work with Edge.)
go here in IE: https://www.magtek.com/changemode/
Enable active X when it pops up, and you can change from hid to keyboard and back.
I have problem with using camera in Windows Phone Silverlight 8.1 application. I want just to initialize camera and see its preview (for now I don't need any photos or video capture). I have found nice and simple example on MSDN and
private CaptureSource captureSource;
private VideoCaptureDevice videoCaptureDevice;
private void InitializeVideoRecorder()
{
try
{
if (captureSource == null)
{
captureSource = new CaptureSource();
var a = captureSource.VideoCaptureDevice;
videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
captureSource.CaptureFailed += OnCaptureFailed;
if (videoCaptureDevice != null)
{
VideoRecorderBrush = new VideoBrush();
VideoRecorderBrush.SetSource(captureSource);
captureSource.Start();
CameraStatus = "Tap record to start recording...";
}
else
{
CameraStatus = "A camera is not supported on this phone.";
}
}
}
catch (Exception ex)
{
CameraStatus = "ERROR: " + ex.Message.ToString();
}
}
The code stops at captureSource.Start(); throwing System.UnauthorizedAccessException: Attempted to perform an unauthorized operation..
First of all I found information (on the same page) that ID_CAP_ISV_CAMERA capability is needed in `WMAppManifest.xml'. But I have problem with adding it, because:
I can't find this capability in designer
I get error when I add it manualy to .xml file
Error reproduced below:
Warning 1 The 'Name' attribute is invalid - The value 'ID_CAP_ISV_CAMERA' is invalid according to its datatype 'http://schemas.microsoft.com/appx/2010/manifest:ST_Capabilities' - The Enumeration constraint failed.
Error 3 App manifest validation failed. Value 'ID_CAP_ISV_CAMERA' of attribute '/Package/Capabilities/Capability/#Name' must be a valid capability.
I have even found the same solution on SO WP8.1 SilverLight Microsoft.Devices.PhotoCamera Access Denied
Can somebody tell me why can't I use original MSDN solution to this problem?
First, it looks like you're trying to add that capability to Package.appxmanifest instead of WMAppManifest.xml. You should be able to find WMAppManifest.xml under Solution Explorer -> <your project> -> Properties:
Opening that file should give you the option to add ID_CAP_* capabilities.
Second, you need to specify both ID_CAP_ISV_CAMERA and ID_CAP_MICROPHONE in order to use CaptureSource.Start(), even if you're only using one of the devices.
In a Xamarin.Forms app I'm using Application.Current.Properties to save settings. When my LoginPage loads I want to see if settings exist but I'm getting an exception saying Application.Current is Null. This is the (sanitized) code, which is in the LoginPage:
private bool AuthTokenExists()
{
// The following line throws the exception
if (Application.Current.Properties.ContainsKey("First") && Application.Current.Properties.ContainsKey("Second"))
{
if (Application.Current.Properties["First"] as string != null &&
Application.Current.Properties["Second"] as string != null)
return true;
}
else
{
return false;
}
}
I've read you can't call Application.Current.Properties in the App constructor, but this is in a ContentPage. Any thoughts why I'm getting the exception? Thanks in advance!
It's null until you call LoadApplication () from your platform projects.
Just wirte LoadApplication( new App() ); in MainActivity.cs and your App class in PCL or Shaired must be a Applciation not a content Page.
Then you can use your exsisting code any where in application (including content page as you mention) , It will not give Null exception.
Right now, there is a (one more :-) bug in the Xamarin-VS extension, so that the application-object is not visible in the debugger.
Therefore, I have filled a bug in bugzilla.
But at RunTime (without debugger) it should run (at least with the newer XF-Versions).
Additionally there are some problems with some devices (e.g. my Android tablet SM-T900), so that the Properties are not stored properly (sounds good:-)
In one of the last XF-Versions, there is now possible, to store the properties explicitly (new method).
So, I suggest you, to:
- Update to the version that allow the explicit store (if not already in use)
- Set default values by app-start
- Save it with the new method
- Deploy to device
- Retest, if it works then (e.g. show a DisplayAlert with the Property-value)
If not, you should fill a bug in BugZilla.
Hope this helps...