I am using Android application with C# ,
My application involved
1-creating database and table
2 insertion-updation-deletion
3-Android 2.1
Application working perfectly in emulator , but after installing successfully in Tablet
i am getting this error during open the application while my tablet also have same android ver2.1.
Here is my some code i want know if something wrong in it ?
using System.Data;
using System.Collections.Generic;
using System.IO;
using Android.OS;
String Path_ = new databse.db().Database("netdobrasil.sqlite");
public string Database(string DbName)
{
var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var pathToDatabase = Path.Combine(documents, "netdobrasil.sqlite").ToString();
SqliteConnection.CreateFile(pathToDatabase);
return pathToDatabase;
}
Related
I'm trying to establish connection to google cloud for media upload
I've used various methods like Setting environment variable, saving json to mongodb , tried directly load json from file and then loading to google functions
libraries:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using DAL;
using MongoDB;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Configuration;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using System.Drawing;
using Newtonsoft.Json;
using MongoDB;
using MongoDB.Driver.Builders;
using MongoDB.Bson;
Method 1: Using Environment Variable.
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS","onfer-gc.json");
var Credential1 = GoogleCredential.GetApplicationDefaultAsync();
Error : Using Environment Variable.
Error reading credential file from location onfer-gc.json: Error deserializing JSON credential data.
Please check the value of the Environment Variable GOOGLE_APPLICATION_CREDENTIALS
Method 2: Load json from file
FileStream stream1 = File.OpenRead("onfer-gc.json");
var Credential = GoogleCredential.FromStream(stream1);
Error deserializing JSON credential data.
Method 3: Loading data from Mongodb database and then trying to turn into string
var Db = new Database();
var result = Db.GetCollection<company>().FindOne(Query.EQ("type", "service_account"));
var Credential = GoogleCredential.FromJson(result);
In this case it gives error
Element 'type' does not match any field or property of class MongoDB.company.
Even I've checked solutions online
https://github.com/google/google-api-dotnet-client/issues/747
But it didn't work. What am i doing wrong here ?
My case may not answer the question directly, but it might be possible cause for such error. In my projects I have references to two different versions of Newtonsoft.json, one is 12.0.2 and the other one is 7.0.1. Once I had 7.0.1 updated to same 12.0.2, the json deserializing error solved. This might explain some random working/not-working situations.
I was successfull establishing connection using Method 2:
string credPath = "D:\\Admin\\gcloudcred.json";
var credential = GoogleCredential.FromStream(File.OpenRead(credPath));
var storageClient = StorageClient.Create(credential);
listvideos = storageClient.ListObjects("bucketname");
if (listvideos == null)
{
return listvideos = listvideos1;
}
return listvideos;
I have been using Microsoft.Speech synthesizer for years on different PCs and different versions of Windows. I am trying to set up the development and support environment on a new Windows 10 PC and I can't get spsynthesizer to work correctly. I have downloaded the Microsoft SDK5.1 and the voices twice now to make sure nothing was corrupted. I have stepped through each line of code with the debugger and everything works as expected until the call to spsynthesizer.speak...the call never speaks and never returns to the program. I have tried executing as x86, x64 and AnyCPU and I have a reference entry to Microsoft.Speech.
Any suggestions? Here is the simple C# test application.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Speech.Synthesis;
namespace test_text_to_speech
{
class Program
{
static void Main(string[] args)
{
Microsoft.Speech.Synthesis.SpeechSynthesizer spsynthesizer = new Microsoft.Speech.Synthesis.SpeechSynthesizer();
System.Collections.ObjectModel.ReadOnlyCollection<Microsoft.Speech.Synthesis.InstalledVoice> myvoices;
myvoices = spsynthesizer.GetInstalledVoices();
spsynthesizer.SelectVoice(myvoices[0].VoiceInfo.Name); //Invoke the one which you want
spsynthesizer.Volume = 100; // Can be 1 - 100
spsynthesizer.Rate = 1; // can be 1 - 10
spsynthesizer.SetOutputToDefaultAudioDevice();
PromptBuilder Thanks = new PromptBuilder();
Thanks.AppendSsmlMarkup("<voice xml:lang=\"en-US\">");
Thanks.StartStyle(new PromptStyle(PromptEmphasis.Strong));
Thanks.AppendText("Hello World");
Thanks.EndStyle();
Thanks.AppendSsmlMarkup("</voice>");
spsynthesizer.Speak(Thanks);
spsynthesizer.Speak("try with no markup");
}
}
}
This code works fine within a Kentico website:
var users = UserInfoProvider.GetUsers();
for (int x = 0; x < users.Count(); x++
{
UserInfo currentUser = users.ElementAt(x);
currentUser.SetValue("AcceptsAlerts", equivalentSubscriber.Status != SubscriberStatus.Unsubscribed);
UserInfoProvider.SetUserInfo(currentUser);
}
When I move the code to a console app, any calls to UserInfoProvider result in the error: "Object type 'cms.usersettings' not found"
For the initial call to get the users, I can do it like this in the console app:
DataSet usersds = new CMS.DataEngine.DataQuery("cms.user.selectall").Execute();
then loop through Table1 of the dataset using the user data:
UserInfo currentUser = new UserInfo(dtUsers.Rows[x]);
All is fine and working, until I come to write the updated user back to the database. I cannot find another way of writing the data apart from calling:
UserInfoProvider.SetUserInfo(currentUser);
Does anyone know another way to save the user data? or to resolve the error. The error is a runtime error and as far as I know, I have referenced everything I need to. The field I am editing is a custom field added to the cmsUser table.
using statements for info:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using CMS;
using CMS.CustomTables;
using CMS.DataEngine;
using CMS.Membership;
Before you start working with Kentico CMS API from an external application make sure you call the following lines:
CMS.DataEngine.ConnectionHelper.ConnectionString = "your connection string";
CMS.Base.SystemContext.WebApplicationPhysicalPath = Application.StartupPath;
CMS.DataEngine.CMSApplication.Init();
Then, you'll be also able to use UserInfoProvider.GetUsers() object query instead of using DataQuery.Execute().
Are you sure you are referencing all necessary assemblies?
Following scenario works on my machine with configuration: Kentico 8.x, Web Application project
Reference in your Console application these assemblies from lib folder
CMS.Base
CMS.DataEngine
CMS.DataProviderSQL
CMS.Membership
Then copy your Connection String from Web Application's web.config to Console Application's App.config.
After that you can use this code to set custom user properties
static void Main(string[] args)
{
var users = UserInfoProvider.GetUsers();
foreach (var user in users)
{
user.SetValue("myTestString", "test");
user.Generalized.SetObject();
}
}
For anyone looking to get a SiteID to use in API calls from an external app such as getting an email template, this might help you. In Kentico 8.1 you can go to Sites > General and get the code name for your site. Then you can do this:
int siteID = CMS.SiteProvider.SiteInfoProvider.GetSiteID("<your site code name>");
Hope it helps!
I´m new to C# -- started three days ago because of an especific need regarding usb drives. Reading here and there I could have the following code to work. What I want is to know when an user inserts a pendrive in the usb port.
The only problem is the that on XP32 (the only XP I tested) the event will never be detected. On Windows 7 it runs perfectly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Diagnostics;
using System.Threading;
using System.IO;
using Microsoft.Win32;
using System.Security.Permissions;
namespace X
{
class Program
{
static void Main(string[] args)
{
ManagementEventWatcher watcher = new ManagementEventWatcher();
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2");
watcher.Query = query;
watcher.Start();
watcher.WaitForNextEvent();
// DO something if a pen drive (or any storage device) is inserted.
// Works fine on Windows 7
// XP will ignore the event...
}
}
}
Any suggestions will be very welcome!
Regards,
Sergio
Looks like you need XP service pack 3 for it to work (SP2 on x64).
I am trying to learn and use an SDK for a vendor's product. Unfortunately, the documentation is sketchy and I've run into a void in my own knowledge of the .Net Framework.
I have some working code for a windows forms application and I am trying to get it working in an ASP.NET web form app. The vendor documentation implies you can do this but maybe you cannot..
Snippet from the working windows app:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using TRIMSDK;
private void ConnectUserBtn_Click(object sender, System.EventArgs e)
{
Database db = new Database();
Databases dbChooser = new Databases();
IDatabase dbI = dbChooser.ChooseOneUI(Handle.ToInt32());
if (dbI == null)
{
return;
}
db.Id = dbI.Id;
Now here is my attempt inside click event handler for an .ASPX page:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TRIMSDK;
protected void ConnectUserBtn_Click(object sender, EventArgs e)
{
Database db = new Database();
Databases dbChooser = new Databases();
IDatabase dbI = dbChooser.ChooseOneUI(Handle.ToInt32());
if (dbI == null)
{
return;
}
I get a compile complaint in the line just above that reads "The name 'Handle' does not exist in the current context.
This part of the SDK I am trying to use displays various modal dialogs that reflect the properties of the product to facilitate "client" development. I fear it might be only "Windows clients" and that ASP.NET web apps cannot do this.
Is there something I can add to resolve this?
For web apps, modal dialogs would be done at the client, usually via javascript and dhtml - not at the server (where ASP.NET code executes). So I fear that this product is indeed winforms only.
Just pass it:
int hwnd = 0;
IDatabase dbI = dbChooser.ChooseOneUI(hwnd);