VCF Vcard import c# - c#

iam trying to write a class which imports *.vcf files (Vcard), because i didn´t found a adequate .net class to solve that job.
So i decided to treat the *.vcf file like a *.txt file. I just import the whole file, line by line, with a StreamReader. Finally i save the line into a List object.
The Code:
private List<string> vcardList = new List<String>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (StreamReader reader = new StreamReader(#"H:\VS.vcf"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
vcardList.Add(line);
}
}
}
After importing the text i needed to edit the lines, because i need to remove all the unnecessary symbols.
I tried to use the RedEx claa:
private void button1_Click(object sender, EventArgs e)
{
vcardList[0] = Regex.Replace(vcardList[0], "BEGIN:", string.Empty);
}
that works very well, for the first line! but the *.vcf file is very complex and allways different.
So my question is: Is there a better way to solve that problem?
This is the *.vcf file:
BEGIN:VCARD
VERSION:2.1
N;LANGUAGE=de;CHARSET=Windows-1252:Test;Mustermann;;;(geschäftlich)
FN;CHARSET=Windows-1252:Test Mustermann (geschäftlich)
ORG:Mustermann CompanyTITLE;CHARSET=Windows-1252:CEO
TEL;WORK;VOICE:0049 1111 22 769 23 - 1
TEL;CELL;VOICE:0049 2222 33 71 55 90
ADR;WORK;PREF;CHARSET=Windows-1252:;;Frobuehl 22;Gothtown;;101092;England
LABEL;WORK;PREF;CHARSET=Windows-1252;ENCODING=QUOTED-PRINTABLE:Leihb=FChl 21=0D=0A=
101092 Frobuehl
X-MS-OL-DEFAULT-POSTAL-ADDRESS:2
URL;HOME:www.Test-Mustermann.de
EMAIL;PREF;INTERNET:Test#Test-Mustermann.de
X-MS-OL-DESIGN;CHARSET=utf-8:<card
END:VCARD
I only need the name and address. Thanks in advance

Pretty old, but it still works: https://github.com/drlongnecker/Thought.vCards

You can try to use this sample.

Helle, sry for the long delay.
I solved my problem now with the follwing code:
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;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Outlook.ContactItem contact;
Outlook.Application app = new Outlook.Application();
contact = (Outlook.ContactItem)app.Session.OpenSharedItem(#"C:\vv.vfc");
MessageBox.Show(contact.FirstName);
}
}
}
This is just an example of how to easily import a VCF file with C# . i hope this helps. Of course i wouldnt implement it in that way, i rather would create a method with a parameter "incomingFile" or smth else.
Berry

the solution with the outlook application is not effictive.
Outlook.Application app = new Outlook.Application();
this will open the outlook first. and actually you need only to open the vcard and parse it to extract the information you want from it.

C# purely does not has specific method or class for work with vcfs.
But these solutions can be way.last one is the best:
Work with Microsot.office.interop.outlook.
Ohhh nooo.it will open outlook first and then after steps you can do your work.surely its not best solution.
Use Thought vcard.its not too bad but image that you have multiple vcfs and you merge them in one vcf.with this package its too hard(or almost impossible) to work with it.
Use VCardlib .it doesnt has previous problem but its not update for work with vcf version4 until now.
I use MixERP.NET.VCard and its more simple and effective.

Related

How to export a snapshot of the Index Field in PDF or JPG in Kofax Capture?

I'm new at Kofax Capture. The question is how to export a snapshot of the Index Field in PDF or JPG in Kofax Capture? Like export signature from document.
The only thing comes into my mind is to code custom export module, but maybe I missed some features which are 'out of the box' or it would be great, if you provide some existing solutions.
Thank you in advance
Sure you can - Recognition scripts have access to zone snippets (small cutouts of an image that represent a zone being processed) and they can process the zone snippets in a custom engine (cf. Developer's Guide). Here's an example to get you started:
using Kofax.AscentCapture.NetScripting;
using Kofax.Capture.CaptureModule.InteropServices;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class Save_Snippet : RecognitionScript {
public Save_Snippet() : base()
{
this.BatchLoading += Save_Snippet_BatchLoading;
this.BatchUnloading += Save_Snippet_BatchUnloading;
}
void Save_Snippet_BatchLoading(object sender, ref bool ImageFileRequired)
{
this.RecognitionPostProcessing += Save_Snippet_RecognitionPostProcessing;
ImageFileRequired = true;
}
void Save_Snippet_BatchUnloading(object sender)
{
this.BatchLoading -= Save_Snippet_BatchLoading;
this.RecognitionPostProcessing -= Save_Snippet_RecognitionPostProcessing;
this.BatchUnloading -= Save_Snippet_BatchUnloading;
}
void Save_Snippet_RecognitionPostProcessing(object sender, PostRecognitionEventArgs e)
{
File.Copy(e.ImageFile, #"C:\temp\test.tiff");
}
}

How can the current barcode scan output the value?

I use a GD4430 handheld scanner from the company Datalogic with the included OPOS driver. With the following code I manage to address the scanner. When I start the program, the scanner becomes active and you can scan. But I can not display the results in a TextBox.
Does anyone see where the error lies?
Visual Studio 2010 C#
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 TestRead
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
axOPOSScanner1.BeginInit();
axOPOSScanner1.Open("USBHHScanner");
axOPOSScanner1.ClaimDevice(0);
axOPOSScanner1.DeviceEnabled = true;
axOPOSScanner1.DataEventEnabled = true;
axOPOSScanner1.PowerNotify = 1; //(OPOS_PN_ENABLED);
axOPOSScanner1.DecodeData = true;
}
void axOPOSScanner1_DataEvent(object sender, AxOposScanner_CCO._IOPOSScannerEvents_DataEventEvent e)
{
textBox1.Text = axOPOSScanner1.ScanDataLabel;
textBox2.Text = axOPOSScanner1.ScanData.ToString();
axOPOSScanner1.DataEventEnabled = true;
axOPOSScanner1.DataEventEnabled = true;
}
}
}
Was not the processing of AxOPOSScanner1.BeginInit() on the source originally in Form1.Designer.cs instead of here?
(I am assuming that the source file name is Form1.cs)
As below(in Form1.Designer.cs):
this.axOPOSScanner1 = new AxOposScanner_CCO.AxOPOSScanner();
((System.ComponentModel.ISupportInitialize)(this.axOPOSScanner1)).BeginInit();
this.SuspendLayout();
There is a possibility that the problem has occurred because you moved it to Form1.cs or calling BiginInit() on both Form1.Designer.cs and Form1.cs.
Or, the following processing does not exist in Form1.Designer.cs, or there is a possibility that the specified function name(axOPOSScanner1_DataEvent) is wrong.
this.axOPOSScanner1.DataEvent += new AxOposScanner_CCO._IOPOSScannerEvents_DataEventEventHandler(this.axOPOSScanner1_DataEvent);
In addition:
What you should do is to temporarily store the return value of all the methods, add a process to determine whether the method was executed normally, likewise It is to read the ResultCode property immediately after setting the property(possibly causing an error) and add processing to judge whether the property setting was done normally.
Also, although not related to DataEvent, PowerNotify setting must be done before DeviceEnabled = true.

C# Thread error

So im attempting to create a auto typer. And the problem is if i spam the message, And click the application to stop the spam it just freezes up. I as then told i need to use Threads. So i had a read around and this is what i came up with:
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.Threading;
namespace tf2trade
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public bool started = true;
private void spam()
{
string test = text1.Text;
Thread.Sleep(2000);
while (started == false)
{
foreach (char c in test)
{
SendKeys.Send(c.ToString());
}
SendKeys.Send("{ENTER}");
}
}
Thread test = new Thread(spam);
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void submit_Click(object sender, EventArgs e)
{
if (started == true)
{
started = false;
submit.Text = "Stop";
submit.Refresh();
spam();
}
else
{
started = true;
submit.Text = "Start";
}
}
}
}
Now this code gives me the error:
A field initializer cannot reference the non-static field, method, or property 'tf2trade.Form1.spam()'
What did i do wrong? :(
Thanks in advance,
Alana.
Honestly I wouldn't waste your time troubleshooting this error. Instead, consider using one of the existing approaches to writing multi-threaded applications in .NET . The technology you use will depend on the type of problem you are trying to solve. For short/quick tasks consider using:
thread pool
.net task library
If you are creating a "long" running task you could create 1 or more native threads, but I wouldn't recommend doing this until you have a better understanding of what you are doing. There are a lot of pitfalls. For example, A lot of developers think more threads equals better performance... this is not true.
REFERENCES
thread pool:
http://msdn.microsoft.com/en-us/library/system.threading.threadpool(v=vs.110).aspx
tasks: http://msdn.microsoft.com/en-us/library/dd460717(v=vs.110).aspx
native thread: http://msdn.microsoft.com/en-us/library/system.threading.thread(v=vs.110).aspx

C# Import data from text file to text boxes

I just want to say that I only joined stackoverflow a few weeks ago and everyone has been very helpful, thank you. I am down to my last two homework assignments for the semester. What I am trying to do right now is import the data I save to a text file from a program I wrote earlier. Basically the text file is named "client.txt" and the data in it looks like this
account#,firstname,lastname,balance
what I am trying to do now is write a windows form that will read the data in that text file and place it into appropriate corresponding text boxes in the form. Here is my code so far, I believe I am on the right track but I am having trouble because I need the program to do a openfiledialog so I can manually choose the client.txt file and then import the data. Right now I am getting an error "System.IO.StreamReader does not contain a constructor that takes 0 arguments"
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.IO;
namespace Chapter_17_Ex.Sample_2
{
public partial class Form1 : Form
{
OpenFileDialog filechooser = new OpenFileDialog();
public Form1()
{
InitializeComponent();
}
private void btnImport_Click(object sender, EventArgs e)
{
StreamReader fileReader = new StreamReader();
string inputrecord = fileReader.ReadLine();
//string filename;
string[] inputfields;
if (inputrecord != null)
{
inputfields = inputrecord.Split(',');
txtAccount.Text = inputfields[0];
txtFirstName.Text = inputfields[1];
txtLastName.Text = inputfields[2];
txtBalance.Text = inputfields[3];
}
else
{
MessageBox.Show("End of File");
}
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
To use a StreamReader you need to construct it passing, at least, the filename to read.
This could be accomplished using the OpenFileDialog variable declared at the form global level
// Show the OpenFileDialog and wait for user to close with OK
if(filechooser.ShowDialog() == DialogResult.OK)
{
// Check if the file exists before trying to open it
if(File.Exists(filechooser.FileName))
{
// Enclose the streamreader in a using block to ensure proper closing and disposing
// of the file resource....
using(StreamReader fileReader = new StreamReader(filechooser.FileName))
{
string inputrecord = fileReader.ReadLine();
string[] inputfields;
....
// The remainder of your code seems to be correct, but a check on the actual
// length of the array resulting from the Split call should be added for safety
}
}
}
Notice that both the OpenFileDialog and the StreamReader are complex objects that have many properties and different ways to work. You really need to look at their constructors and properties list in the MSDN documentation to exploit their full functionality

Why is the program form not loading when accessing file?

With the below code, I've tested it out and the loading of the form works fine standalone, but when the program goes to check if a file exists, the form doesn't load properly and I'm at a loss as to what to do. Is there another method of checking to see if a file exists that I could use in this instance?
EDIT I've made a new 'startup' form to run the file exists check, but it still doesn't work. Again the form loads, but the contents of the form don't and the form itself freezes.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Timers;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;
using System.Windows.Input;
namespace program1
{
public partial class Startup : Form
{
public Startup()
{
InitializeComponent();
}
private void Startup_Load(object sender, EventArgs e)
{
notifyIcons norm = new notifyIcons();
Settings set = new Settings();
set.Show();
string curFile = Environment.CurrentDirectory + "\\age.txt";
if (File.Exists(curFile))
{
norm.Show();
this.Close();
}
else
{
set.Show();
for (;;)
{
if (File.Exists(curFile)) norm.Show(); this.Close();
Application.DoEvents();
}
}
}
}
}
I have no idea what this code is supposed to do.. but I can tell you why its not working.
while (ageFileExists)
That is never false. Therefore, your loop will continually loop... forever. You need to set it false somehow in the loop. I have no idea what sort of rules govern that though.
The reason the form doesn't load is because the loop never exits.. and so the message loop that makes the window do anything can never continue processing window messages.
If you can give more context around what you're trying to do I could help you with a proper solution. As it stands though, I can only see the problem.
while(ageFileExists)
{
if (File.Exists(curFile)) ageFileExists = true;
set.WindowState = FormWindowState.Normal;
}
If that file exists you have an infinite loop. You never set ageFileExists to false and that loop does nothing at all. And where does that label go? I seriously doubt you need to be using goto. Your code doesn't make much sense as it stands.
By using the following code in the main form, it seemed to work a treat! I think the critical part was Application.DoEvents();
Thanks for all of your assistance
InitializeComponent();
set.Show();
set.WindowState = FormWindowState.Minimized;
string curFile = Environment.CurrentDirectory + "\\age.txt";
if (File.Exists(curFile)) goto Labelx;
set.WindowState = FormWindowState.Normal;
for (; ; ) { Application.DoEvents(); if (File.Exists(curFile)) break; }
set.WindowState = FormWindowState.Minimized;
Labelx:TextReader reader = File.OpenText(Environment.CurrentDirectory + "\\age.txt");

Categories

Resources