473,387 Members | 1,700 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,387 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 1998
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 =...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.