473,381 Members | 1,435 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

Missing first 2 charcters of file name in win ce(.net cf 2.0) using findfirstfile

4
hi,

My code works but i am missing the first 2 characters of file name.
Any idea why????

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.Threading;
  10.  
  11.  
  12. namespace dummy2
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         int rfidTagHandle;
  17.         Win32Methods.WIN32_FIND_DATA FindFileData;
  18.  
  19.  
  20.  
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.  
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  28.  
  29.             rfidTagHandle = Win32Methods.FindFirstFile("\\*.*", out FindFileData);
  30.             //"\\RFID\\[.]"
  31.             if (rfidTagHandle == Win32Methods.INVALID_HANDLE_VALUE)
  32.             {
  33.                 MessageBox.Show("FindFirstFile failed");
  34.  
  35.             }
  36.             else
  37.             {
  38.  
  39.                 //Byte[] fileName =FindFileData.cFileName;
  40.                 //string filen = System.Text.UnicodeEncoding.Unicode.GetString(fileName, 0, fileName.Length);
  41.                 //StringBuilder cb = new StringBuilder(256);
  42.                 //cb = FindFileData.cFileName;
  43.                 string filen = FindFileData.cFileName;
  44.                 textBox1.Text = textBox1.Text + filen + "\r\n";
  45.             }
  46.  
  47.             while (Win32Methods.FindNextFile(rfidTagHandle, out FindFileData) != false)
  48.             {
  49.                 //Byte[] fileName = FindFileData.cFileName;
  50.                 //string filen = System.Text.UnicodeEncoding.Unicode.GetString(fileName, 0, fileName.Length);
  51.                 //StringBuilder cb = new StringBuilder(256);
  52.                 //cb = FindFileData.cFileName;
  53.                 string filen = FindFileData.cFileName;
  54.                 textBox1.Text = textBox1.Text + filen + "\r\n";
  55.  
  56.  
  57.             }
  58.             MessageBox.Show("FindnextFile failed");
  59.             Win32Methods.FindClose(rfidTagHandle);
  60.  
  61.         }
  62.  
  63.  
  64.     }
  65.  
  66.     public class Win32Methods
  67.     {
  68.  
  69.         public const int INVALID_HANDLE_VALUE = -1;
  70.         //, CharSet = CharSet.Unicode
  71.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  72.         public struct WIN32_FIND_DATA
  73.         {
  74.             public uint dwFileAttributes;
  75.             public FILETIME ftCreationTime;
  76.             public FILETIME ftLastAccessTime;
  77.             public FILETIME ftLastWriteTime;
  78.             public uint nFileSizeHigh;
  79.             public uint nFileSizeLow;
  80.             public uint dwReserved0;
  81.             public uint dwReserved1;
  82.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
  83.             public string cFileName;
  84.             //[MarshalAs(UnmanagedType.LPStr)]
  85.             //public StringBuilder cFileName;
  86.             //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 260)]
  87.             //public Byte[] cFileName;
  88.             //[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
  89.             //public string cAlternateFileName;
  90.  
  91.         };
  92.  
  93.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  94.         public struct FILETIME
  95.         {
  96.             public uint dwLowDateTime;
  97.             public uint dwHighDateTime;
  98.         };
  99.  
  100.         //Findfirstfile
  101.         [DllImport("coredll.dll", CharSet = CharSet.Auto,SetLastError = true)]
  102.         public static extern int FindFirstFile(string szSearchFile,out WIN32_FIND_DATA lpFindFileData);
  103.  
  104.         //FindNextFile
  105.         [DllImport("coredll.dll",CharSet = CharSet.Auto, SetLastError = true)]
  106.         [return: MarshalAs(UnmanagedType.Bool)]
  107.         public static extern bool FindNextFile(int hFindFile,out WIN32_FIND_DATA lpFindFileData);
  108.         //Findclose
  109.         [DllImport("coredll.dll",CharSet = CharSet.Auto, SetLastError = true)]
  110.         [return: MarshalAs(UnmanagedType.Bool)]
  111.         public static extern bool FindClose(int hFindFile);
  112.     }
  113.  
  114. }
Nov 28 '07 #1
3 1997
Plater
7,872 Expert 4TB
Why are you doing all of that with unmanaged code?
What was wrong with:
Expand|Select|Wrap|Line Numbers
  1. Directory.GetFiles(Path, pattern);
  2.  
???
System.IO is still in CF2
Nov 28 '07 #2
gudiya
4
actually I have a handheld reader which has a file system and starts reading rfid tags using the command findfirst file
Nov 29 '07 #3
Plater
7,872 Expert 4TB
EDIT: WOW I can't believe I missed that.
You're using a Unicode conversion, it's probably treating the first two characters as the byte-order mark.
Try using the ASCII encoding and see what you get?
Nov 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
2
by: tom | last post by:
Hello, I want to know if FindFirstFile() can do more as I expect. FindFirstFile() can take the arguement of "*" or "?", for example, FindFirstFile("result.*.txt", &FileData); I want to...
1
by: Paulo Eduardo | last post by:
Hi, all! We are devleping one app that will use disk access with FindFirstFile and FindNextFile for it. Can someone expose me how works FindFirstFile and FindNextFile in disk access? Does the...
14
by: tshad | last post by:
I am trying to set up a reusable library (business component) that I can use in a bunch of my pages. I built the file and it almost compiles, but I am not sure what I am missing. The vbc...
4
by: Jason | last post by:
I need to open a file for reading, but I only know part of it's name. The file I want to read is in the format of xxx-yyyy-zzz.EXT The last three digits of the file name are different on each...
13
by: Andrew | last post by:
Hello, I am trying to find a way to take the contents of a directory and write it into a file. I have a directory that has several hundred text files, and I want to create a file containing all...
2
by: im2cre8iv | last post by:
Here is my code where I am receiving the error: #include <fstream> #include "BinaryTree.h" using namespace std; Node* BinaryTree::MakeTree(ifstream& infile) { char name; infile>>name;
4
by: William Krick | last post by:
Given these two code snippets, the first generates errors, the second doesn't... // generates errors $tboard = $context; $tboard = empty($tboard)?'':' - '.$tboard; $ttopic = $context; $ttopic...
0
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.