|
That's pretty much what the Remarks section in the MSDN page says will happen. When I run it on my PC it returns my PC name.
|
|
|
|
|
What I'm trying to accomplish is to determine if the app is being run on our network. The users will VPN in, then run the app. I need to check that their connected before continuing to let app load.
I've also tried "Dns.GetHostAddresses("www.the_domain.com").FirstOrDefault()". This returns a 192.168.... address.
Any idea how to check if the user is VPN's in from an Android app?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
As far as I am aware, this will always return the address related to the system on which the app is running. It's a while since I did this for real.
|
|
|
|
|
|
hi kevin,
you can use IP api to get the isp name,
if the user is connected to VPN then ip will match with the ISP
e.g. https://ipinfo.io/
=====================================================
The grass is always greener on the other side of the fence
|
|
|
|
|
Can someone help how I can also copy user's desktop folder's subfolders and their files with the code below this text?
For moment I can only copy files from \" + computer + "\c$\Users\Desktop folder but not the subfolders and their files.
string[] dirs = Directory.GetDirectories("\\\\" + computer + "\\c$\\Users\\");
foreach (string item in dirs)
{
FileInfo f = new FileInfo(item);
user2 = "\\\\" + computer + "\\c$\\Users\\"+ f.Name + "\\Desktop";
if (Directory.Exists(user2))
{
user = "C:\\Backup\\" + computer + "\\" + f.Name + "\\Desktop";
Directory.CreateDirectory(user);
DirectoryInfo folder = new DirectoryInfo(user2);
FileInfo[] files = folder.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(user, file.Name);
file.CopyTo(temppath, true);
}
}
modified 15-Nov-18 12:00pm.
|
|
|
|
|
What exactly is happening, and why not just use "C:\Users\ ..."?
|
|
|
|
|
Hi,
what you need is a recursive method (say DeepCopyDir()) that copies an entire folder by:
(1) copying its files, using Directory.GetFiles and File.Copy for each of them;
(2) copying its subfolders, using Directory.GetDirectories and DeepCopyDir for each of them.
|
|
|
|
|
Hi all, first of all I'm a novice when it comes to parsing Json , I'm attempting ( with some success ) to get information from the OED API, this is my first attempt
using System;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json.Linq;
namespace OxfordDictionary
{
class Program
{
static HttpWebRequest req = null;
static string PrimeUrl = "https://od-api.oxforddictionaries.com:443/api/v1/entries/en/";
static string uri = PrimeUrl + "crossword";
static string theJson = "";
static HttpWebResponse HWR_Response = null;
static Stream respStream = null;
static StreamReader sr = null;
static void Main(string[] args)
{
req = (HttpWebRequest)HttpWebRequest.Create(uri);
req.Headers.Add("app_id", "my id");
req.Headers.Add("app_key", "app key");
req.Method = WebRequestMethods.Http.Get;
req.Accept = "application/json";
HWR_Response = (HttpWebResponse)req.GetResponse();
respStream = HWR_Response.GetResponseStream();
sr = new StreamReader(respStream, Encoding.UTF8);
theJson = @sr.ReadToEnd();
sr.Close();
var results = JObject.Parse(theJson)["results"];
string value = "";
string name = "";
string output = "";
foreach (JObject o in results.Children<JObject>())
{
foreach (JProperty p in o.Properties())
{
name = p.Name;
foreach (var v in p.Values())
{
value = v.ToString();
output += value;
}
}
}
Console.WriteLine(output);
Console.ReadKey();
}
}
}
which returns
crossword{
"entries": [
{
"etymologies": [
"said to have been invented by the journalist Arthur Wynne, whose puzzle (called a ‘word-cross’) appeared in a Sunday newspaper, the New York World, on 21 December 1913"
],
"grammaticalFeatures": [
{
"text": "Singular",
"type": "Number"
}
],
"homographNumber": "000",
"senses": [
{
"definitions": [
"a puzzle consisting of a grid of squares and blanks into which words crossing vertically and horizontally are written according to clues"
],
"domains": [
"Games"
],
"examples": [
{
"text": "she settled down to do the crossword"
}
],
"id": "m_en_gbus0236440.007",
"short_definitions": [
"puzzle consisting of grid of squares and blanks into which words crossing vertically and horizontally are written according to clues"
]
}
],
"variantForms": [
{
"text": "crossword puzzle"
}
]
}
],
"language": "en",
"lexicalCategory": "Noun",
"pronunciations": [
{
"audioFile": "<a href="http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3">http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3</a>",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "ˈkrɒswəːd"
}
],
"text": "crossword"
}headwordcrossword
the bit I'm interested in is
"definitions": [
"a puzzle consisting of a grid of squares and blanks into which words crossing vertically and horizontally are written according to clues"
I've tried googling but can't find anything to help me, so my question is ? how can I parse definitions[0] ?
We can’t stop here, this is bat country - Hunter S Thompson RIP
modified 15-Nov-18 10:03am.
|
|
|
|
|
The first thing to note is that there are three problems with the JSON data:
1) Remove the introductory "crossword"
2) Remove the trailing "headwordcrossword"
3) Escape the double quotes in the "audiofile" href:
"audioFile": "<a href="http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3">http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3</a>", To:
"audioFile": "<a href=\"http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3\">http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3</a>",
When you do that, it'll parse fine.
There is an online JSON to C# class converter I use: json2csharp - generate c# classes from json[^] which gives me these classes:
public class GrammaticalFeature
{
public string text { get; set; }
public string type { get; set; }
}
public class Example
{
public string text { get; set; }
}
public class Sens
{
public List<string> definitions { get; set; }
public List<string> domains { get; set; }
public List<Example> examples { get; set; }
public string id { get; set; }
public List<string> short_definitions { get; set; }
}
public class VariantForm
{
public string text { get; set; }
}
public class Entry
{
public List<string> etymologies { get; set; }
public List<GrammaticalFeature> grammaticalFeatures { get; set; }
public string homographNumber { get; set; }
public List<Sens> senses { get; set; }
public List<VariantForm> variantForms { get; set; }
}
public class Pronunciation
{
public string audioFile { get; set; }
public List<string> dialects { get; set; }
public string phoneticNotation { get; set; }
public string phoneticSpelling { get; set; }
}
public class RootObject
{
public List<Entry> entries { get; set; }
public string language { get; set; }
public string lexicalCategory { get; set; }
public List<Pronunciation> pronunciations { get; set; }
public string text { get; set; }
} Add those to your app, and try Newtonsoft JSOn parser - it should be a single line of code! Json.NET - Newtonsoft[^]
Give it a try - it normally works very nicely for me!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Cheers Paul
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
Hi Paul , very cool class generator but I'm having problems deserialisingn the Json ( all members are null ), the output I show here is not accurate as no href or other tags are present ( maybe it's this site adding them but they are not present in the returned text) so ignore them
{
"metadata": {
"provider": "Oxford University Press"
},
"results": [
{
"id": "crossword",
"language": "en",
"lexicalEntries": [
{
"entries": [
{
"etymologies": [
"said to have been invented by the journalist Arthur Wynne, whose puzzle (called a ‘word-cross’) appeared in a Sunday newspaper, the New York World, on 21 December 1913"
],
"grammaticalFeatures": [
{
"text": "Singular",
"type": "Number"
}
],
"homographNumber": "000",
"senses": [
{
"definitions": [
"a puzzle consisting of a grid of squares and blanks into which words crossing vertically and horizontally are written according to clues"
],
"domains": [
"Games"
],
"examples": [
{
"text": "she settled down to do the crossword"
}
],
"id": "m_en_gbus0236440.007",
"short_definitions": [
"puzzle consisting of grid of squares and blanks into which words crossing vertically and horizontally are written according to clues"
]
}
],
"variantForms": [
{
"text": "crossword puzzle"
}
]
}
],
"language": "en",
"lexicalCategory": "Noun",
"pronunciations": [
{
"audioFile": "<a href="http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3">http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3</a>",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "ˈkrɒswəːd"
}
],
"text": "crossword"
}
],
"type": "headword",
"word": "crossword"
}
]
}
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
It's probably the "audiofile" entry - it's still got spurious double quotes:
"audioFile": "<a href="http:// ... .mp3">http:// ... .mp3</a>",
^ ^ They terminate the string as far as JSON is concerned an need to be escaped.
I'd suggest a simple regex?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If it helps, this works for me with your data:
string jsonText = File.ReadAllText(@"D:\Test Data\Crossword.json");
Regex regex = new Regex("(\"<a href=\"http://)(.*?)(\">)", RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
jsonText = regex.Replace(jsonText, "\"<a href=\\\"http://$2\\\">");
RootObject ro = JsonConvert.DeserializeObject<RootObject>(jsonText);
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Don't know why but I'm still getting null properties - the object isn't null though
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
I think you need to look closely at exactly the JSON you are processing - it may have other faults!
How different is it to the samples you have been giving?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That is what's so strange, I put the same data you used into a file and copied your code - no error but null properties
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
Ah! If you regenerate the classes from the genuine data you get an extra class called Metadata which changes your RootObject class:
public class Metadata
{
public string provider { get; set; }
}
public class GrammaticalFeature
{
public string text { get; set; }
public string type { get; set; }
}
public class Example
{
public string text { get; set; }
}
public class Sens
{
public List<string> definitions { get; set; }
public List<string> domains { get; set; }
public List<Example> examples { get; set; }
public string id { get; set; }
public List<string> short_definitions { get; set; }
}
public class VariantForm
{
public string text { get; set; }
}
public class Entry
{
public List<string> etymologies { get; set; }
public List<GrammaticalFeature> grammaticalFeatures { get; set; }
public string homographNumber { get; set; }
public List<Sens> senses { get; set; }
public List<VariantForm> variantForms { get; set; }
}
public class Pronunciation
{
public string audioFile { get; set; }
public List<string> dialects { get; set; }
public string phoneticNotation { get; set; }
public string phoneticSpelling { get; set; }
}
public class LexicalEntry
{
public List<Entry> entries { get; set; }
public string language { get; set; }
public string lexicalCategory { get; set; }
public List<Pronunciation> pronunciations { get; set; }
public string text { get; set; }
}
public class Result
{
public string id { get; set; }
public string language { get; set; }
public List<LexicalEntry> lexicalEntries { get; set; }
public string type { get; set; }
public string word { get; set; }
}
public class RootObject
{
public Metadata metadata { get; set; }
public List<Result> results { get; set; }
} I get full data with that.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Success !!! - thanks very much - what a mess Json is when you start dealing with arrays - the code is truly horrible just to get a single value, if it wasn't for JsonConvert.DeserializeObject and the cool class generator I wouldn't bother with it - thanks once again - do I need to flag this a success ? I've never used this forum before only the Q&A <groan> where you accept the answer
A welshman tolerating England
We can’t stop here, this is bat country - Hunter S Thompson RIP
modified 16-Nov-18 5:30am.
|
|
|
|
|
You're welcome!
I quite like JSON - provided you are working with the same classes in the source and destination it works pretty seamlessly. I prefer it to XML which is pretty nasty to parse manually when it doesn't work...
No, there is no "accept" in the forums, they are just like the Lounge!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yes I can see why it's popular but "Provided your using the same" is a big if
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
Just remembered a not so well known trick in VS, if you create an empty file and paste special from the Edit menu ( with json or xml in the clipboard ), you have the option of pasting json or xml which creates classes for you ( like your online site does ) very useful - just sayin
We can’t stop here, this is bat country - Hunter S Thompson RIP
modified 16-Nov-18 10:11am.
|
|
|
|
|
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 System.Data.OleDb;
namespace Login
{
public partial class Registration : Form
{
private OleDbConnection connection = new OleDbConnection();
public Registration()
{
InitializeComponent();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\VB projects\Project\DataBase\OnlineRetailDataBase.accdb;
Persist Security Info=False;";
}
private void btn_Submit_Click(object sender, EventArgs e)
{
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "INSERT into OnlineRetailDataBase (FirstName, SurName, DateOfBirth, Gender, BankName, BankAccountNumber, Email, Password) VALUES ('" + txt_Fname.Text + "','" + txt_Surname.Text + "','" + txt_dob.Text + "','" + txt_Gender.Text + "','" + txt_Bname.Text + "','" + txt_ban.Text + "','" + txt_Email.Text + "','" + txt_Password.Text + "',)";
command.ExecuteNonQuery();
MessageBox.Show("You Now Registered, Please Login");
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
connection.Close();
}
}
private void txt_Fname_TextChanged(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
Don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT
DROP TABLE MyTable; A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
Fix that throughout your app, and the chances are your problem will disappear at the same time.
And while you are here ... there is another bigger change you need to make: Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
And a smaller one: don't store dates in string based columns - valide your DOB by using TryParse to convert it to a DateTime value, and pass that as a parameter to your DB. In the DB, use a DATETIME, DATETIME2, or DATE column to store it, not a VARCHAR or NVARCHAR. And do that now, before you have a backlog of bad dates to deal with because they will cause you enormous problems in the future if you don't.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
//OleDb Connection String.
private int EditID = 0;
private static string Connection = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + @"\PostalDBS.accdb";
if (EditID == 0)
{
OleDbConnection con = new OleDbConnection(Connection);
OleDbCommand com = new OleDbCommand("Insert Into ["+cbobxco1f1.Text.ToString()+"] (ID,name,lastname,coname,handinto,handindate,handoverto,unit,parcelrecieve,Description) Values (@ID, @name,@lastname,@coname,@handinto,@handindate,@handoverto,@unit,@parcelrecieve,@Description)", con);
com.Parameters.AddWithValue("@ID", txtrwno1f1.Text);
com.Parameters.AddWithValue("@name", txtname1f1.Text);
com.Parameters.AddWithValue("@lastname", txtfam1f1.Text);
com.Parameters.AddWithValue("@coname", txtco1f1.Text);
com.Parameters.AddWithValue("@handinto", txthndin1f1.Text);
com.Parameters.AddWithValue("@handindate", txthndodate1f1.Text);
com.Parameters.AddWithValue("@handoverto", hndover1f1.Text);
com.Parameters.AddWithValue("@unit", txtunit1f1.Text);
com.Parameters.AddWithValue("@parcelrecieve", chbxparcel1f1.Checked);
com.Parameters.AddWithValue("@Description", txtdescrip1f1.Text);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
//Note: Make sure that you have installed database engine provider based on your OS(*64 or *86)
//This work perfect for me with office v2010.
modified 16-Nov-18 12:03pm.
|
|
|
|
|