Send SMS Text Message - Windows Mobile Software Development

Hi Everyone,
I'm making a WinMo app that will help all those affected by Alzheimer's Disease, as well as its related illnesses. More information is at
JamesGeddes.com/TrackNan
It sends an SMS text to 1 or more mobile numbers when the patient goes outside of the GPS boundary, the only trouble is I can't work out how to get it to send SMS Text messages!
Any help would be fantastic as it will help this most worthy cause - I'll even come and buy you a drink if I can!
Thanks everyone!
James

Hey,
Is this program going to be run on Windows Mobile based phones / PPC or on a Personal Computer?
If it is on a phone, your choices are:
Using .NET CF:
Obtain GPS data (if a class is provided, i am not sure) and based on that data create an OutlookSession and Send a SMS with Microsoft.WindowsMobile.PocketOutlook
P\Invoke a C++ Method (http://msdn.microsoft.com/en-us/library/aa920513.aspx)
Using C++:
Use the methods i just mentioned before, except in a true C++ environment.
Otherwise, I have developed an application called CMail which will send SMS for you when it is run (Check my Signature for some of my projects) All you would need is a way to gather the GPS Data.
If it is on a PC:
I would reccomend looking up pre-set servers that send out SMS and make an app to link to those (just google and you will find ) ...
or you can send 'Email SMS' to phones.... IE: my number is 111-222-3333 and i use Tmobile...so you would email it to [email protected] (or .net? I cant remember)... THe list of these emails IS online
I hope this helps! (I think you are making a program for a great cause!)
Good Luck!

Hi,
I'll be running it on my HTC HD2, so on a Windows Mobile Phone. I'm working in C# and Microsoft have been unusually kind and given GPS code away with the WinMo6 SKD, so thats all good, however I just can't work out how to send a text!
Thanks!
James

It is really easy actually!
Just add a reference to your project for Microsoft.WindowsMobile.PocketOutlook. Then use the following:
Code:
SmsMessage x = new SmsMessage(RECIPIENT NUMBER, BODY);
x.send();
And that should do it!!
Hope this helps

I've use the following code
Code:
private void btn_send_Click(object sender, EventArgs e)
{
SmsMessage x = new SmsMessage(tb_Number, tb_Message);
x.send();
}[code]
However it returns
"The type or namespace name 'SmsMessage' could not be found (are you missing a using directive or an assembly reference?)"
What's going wrong?

OK, I got that working, I just forgot to put this at the top!
Code:
using Microsoft.WindowsMobile.PocketOutlook;
How do you send to multiple numbers though? I've asked the user to give me 3 mobile numbers in coma separated format, does that help?

well you can do a foreach loop
...
SO the user gives you 3 numbers :
123-456-7890
098-765-4321
132-465-7980
Store those to a String[]
Code:
string[] numbs = {1234567890, 09876543210, 1324657980};
foreach (string numb in numbs)
{
SmsMessage x = new SmsMessage(numb, BODY);
x.send();
}
That should do it. I had a few issues when i tried this with my program that i am upgrading ... It may give u a ArgumentException Invalid Address, but it still sends the SMS. To get rid of this just do the following:
Code:
string[] numbs = {1234567890, 09876543210, 1324657980};
try
{
foreach (string numb in numbs)
{
SmsMessage x = new SmsMessage(numb, BODY);
x.send();
}
}
catch {}

I found that sending an SMS took a little while - not too long, maybe about a second or something; but if you're sending to lots of people, the application may stop for a while.
I thought it would be better to use the "for each" idea Cyclonezephyrxz7 mentioned, and put it in a separate thread. I had alsorts of fun with it, but I found the answer.
I wrote something about it here:
http://forum.xda-developers.com/showthread.php?t=630537
I can post the code if you like (I've not got it here), but I wrote it in VB - it should be an easy port.
What this does is to allow your app to continue, while in the background the SMSs get sent - then the code raises an event when done.
Let me know, ok?
Paul.

Related

make call

i want to make a call from my application, please help
PS: i am using .net cf
thanx
Use "phoneMakeCall "function
Find "phoneMakeCall" function infomation in MSDN library.
I was unable to find that function in the MSDN library. I found more, but they were .NET functions.
I am interested in the same functionality as the tel: protocol. Does anyone know what the parameter is that I can send to cprog.exe so it knows what number I want to dial (if it's possible). And if there is a way to make the phone automatically dial that number would be great.
The tel: protocol is really kind of weak for applications outside of IE. Having to launch a blank window is a horrible user experience.
Thanks in advance,
-- Mike
Hi there
Try this link:
http://smartdevices.microsoftdev.com/Learn/Articles/622.aspx
Discribed is a away to use the TAPI through p/Invoke.
It was a bit of hard work, but after only 1/2 a Day i made my first phonecall to a telephonenumber, stored in my App's database.
Generally i found out, that http://smartdevices.microsoftdev.com is a good starting point for searching information (and of course this forum ;-))
Hi
Thx for the link, It helped me a lot. I didn't get the VB.NET part of the sample code (Downloaded) to work when I was calling a phone number. It seems that the phone is not converted correctly. The SMS part of the VB sample works ok although.
The CS sample work OK, I could make a phone call in minuts, using the sample code.
So if I can't find the reason for the error in the VB sample, I must stick to the CS code.
Klaus E. Frederiksen, Denmark
PhoneMakeCall
This function dials the specified phone number.
LONG PhoneMakeCall(
PHONEMAKECALLINFO *ppmci);
Parameters
ppmci
Pointer to the PHONEMAKECALLINFO structure that contains the information related to the call to be placed.
Return Values
Value Description
Non-zero The function was not successful.
Zero The function was successful.
Remarks
This function must be called in order to initiate a phone call.
Guest said:
I was unable to find that function in the MSDN library. I found more, but they were .NET functions.
I am interested in the same functionality as the tel: protocol. Does anyone know what the parameter is that I can send to cprog.exe so it knows what number I want to dial (if it's possible). And if there is a way to make the phone automatically dial that number would be great.
The tel: protocol is really kind of weak for applications outside of IE. Having to launch a blank window is a horrible user experience.
Thanks in advance,
-- Mike
Click to expand...
Click to collapse
Details for .Net developers:
The PhoneMakeCall function is not the tricky part of this.
For .net newcomers it's P/Invoke that makes this a little more difficult,
than just using a dll.
1. You have to create a Class (for Example: Phone) that hold the functionality. Because we are using P/Invoke, don't forget using System.Runtime.InteropServices!
2. In your new created Phone Class declare 2 statics, that help us with the option of Prompting before making a call, one of them will fill the dwFlags part of our Infostructure:
private static long PMCF_DEFAULT = 0x00000001;
private static long PMCF_PROMPTBEFORECALLING = 0x00000002;
3. Now to define the allready by yrj mentioned PhoneMakeCallInfo structure. it should look like this:
private struct PhoneMakeCallInfo
{
public IntPtr cbSize;//size of struct
public IntPtr dwFlags;//prompt or not
public IntPtr pszDestAddress;//pointer to CharArray with
//Phone number
public IntPtr pszAppName;//nothing
public IntPtr pszCalledParty;//nothing
public IntPtr pszComment;//nothing
}
4. The import of the Phone.dll function should be no problem:
[DllImport("phone.dll")]
private static extern IntPtr PhoneMakeCall(ref PhoneMakeCallInfo ppmci);
5. Now you have to create a fucntion that instantiates a PhoneMakeCall infoStructure and call the newly Invoked PhoneMakeCall-function.
Now, have fun!

how to get the notification when a call end

How to get the call process notification when a call end or shut down by remote network?
i don't want to use ril.lib.
If you make the call using ExTAPI (not RIL) then you will get a Callback then the call is over.
Search for 'lineCallbackFunc'.
Ben
It is relatevelly easy with lineCallbackFunc. You have to wait for the LINECALLSTATE_DISCONNECTED messages in dwParam1 of this function and than you have to check the second param to see what cause this event.
The code migth look like this:
case LINECALLSTATE_DISCONNECTED:
{
//Place your code here
switch(dwParam2)
{
case LINEDISCONNECTMODE_NORMAL:
//Place Your code here
}
}
Search MSDN for the list of LINEDISCONNECTMODE constants !!! (I wrote only one, there are more, of course
Regards
Yes, sorry I didn't ellaborate much I use much the same.
This function has six parameters, a random selection of which might contain information, which may or may not be documented. There are various incomplete examples from various people arround, or just dive in and see what you get...
This callback is (I belive) called from the RIL callback. The mapping is not 1-2-1, MS claim there is 'significant logic' between the two layers. So using RIL would ultimatelly get you closer to the truth. Certainly, I belive TAPI only gives access to your applications use of the phone, I belive RIL gives access to any applications use of any phone use.
Some help from TAPI.h where the messages are defined, may be found.
Anyway, this is what I use: First the 'dwMsg' = LINE_CALLSTATE, then examine the dwParam1, dwParam2. When dwParam1 = LINECALLSTATE_DISCONNECTED and dwParam2 != LINEDISCONNECTMODE_REJECT you have a fair chance that the phone has been disconnected.
The hard part is not the understaning of the callback, it's getting bl**dy call back correctly registered in the first place...
Ben

WM (6.5) - Send SMS AND copy them into the "sent messages" folder

Hello,
I'm developing an application for windows mobile 6.5. Im writing the code in c#.net and want to send sms due to my app.
I checked out the POOM and sms sending worked fine.
Code:
SmsMessage msg = new SmsMessage();
msg.To.Add(receiver);
msg.Body = messageText;
msg.Send();
But there's one problem. I want that the messages will be saved/copied to the "send messages" folder, after my program has sent them.
How can I realize that. Is it possible with the POOM, oder should I work with MAPI and generate a converted copy of the msg-Object in the "send messages"-folder?
greets,
raffi
p.s.: Please excuse my english. I'm a german pupil and I knwo that my english isn't the best. So if you got in trouble, while reading my post, ask me and I'll try to explain the problematic part in another way...
I dont know how to implement the code, but I believe that it involves the SmsAccount class and the Folder class. I have seen examples online showing something like :
Code:
SmsAccount x;
Folder outbox;
outbox = x.outbox;
or something of the likes, but I cannot produce that code when making my own program without getting errors about undefined properties, etc. THe MSDN site is pretty useless on this topic too. It seems as tho the Microsoft.WindowsMobile class and its subclasses are under-documented...

Help me understand C++ code with notifications (beers offered)

Hi,
I need to use the C++ version of this. The code should gather information and show this in a notification.
The notification works but I want to receive the choice the user made in the html form.
I know I need to use the hwsink, a message map, and some events but cannot find info (book, example, etc.) how.
Could some one finish this code so I can test what has been chosen. If NOT, please give me an C++ example from which I can learn/copy. I have been searching on google for days now
Thx, for your help
BTW:
I started with this http://www.krvarma.com/?p=146 downloaded code but was a bit to complicated. In it is all I need but i would like it to be in 1 cpp file.
I'm offering 2 beers if you have the solution
Code:
#include "stdafx.h"
#include <stdlib.h>
#include "resource.h"
// {4E8A9888-D15C-4395-9C9A-B4B572F20081}
static const GUID NOTIFICATION_GUID =
{ 0x4e8a9888, 0xd15c, 0x4395, { 0x9c, 0x9a, 0xb4, 0xb5, 0x72, 0xf2, 0x0, 0x81 } };
int _tmain(int argc, _TCHAR* argv[])
{
SHNOTIFICATIONDATA stcNtData = {0};
stcNtData.cbStruct = sizeof(stcNtData);
stcNtData.dwID = 1;
stcNtData.npPriority = SHNP_INFORM;
stcNtData.csDuration = 15;
// stcNtData.hicon = LoadIcon((HINSTANCE)GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON2));
stcNtData.clsid = NOTIFICATION_GUID;
//What todo here... stcNtData.hwndSink = hWnd;
stcNtData.grfFlags = SHNF_SILENT | SHNF_TITLETIME | SHNF_CRITICAL | SHNF_FORCEMESSAGE;
stcNtData.pszTitle = L"ReRemind";
//stcNtData.pszHTML = TEXT("<html><body>This is a sample application to show the SHNotificationAdd API")
// TEXT("<p><b>This line should be bold</b>.<br><i>This one should be italics.</i><br>")
// TEXT("This is a line with a <a href='cmd:10000'>link</a></p>")
// TEXT("<p>This is a line with <input type='button' name='cmd:10001' value='Click'></p><br><br><br><br>");
stcNtData.pszHTML = TEXT("<form method='get' action='TestBubble://Test'>")
TEXT("<table width=100% cellspacing=0 cellpadding=0>")
TEXT("<tr><td colspan=2>")
TEXT("<b>Choose a fruit:</b><p>")
TEXT("<input type='radio' value='0' id='Apples' checked name='Fruit'><label for='Apples'>Apples</label><br>")
TEXT("<input type='radio' value='1' id='Oranges' name='Fruit'><label for='Oranges'>Oranges</label></p></td><td>")
TEXT("<input type='submit' value='Submit' name='Submit'>")
TEXT("</td></tr><tr><td width=42>")
TEXT("<a href='cmd:12288'>Settings</a></td></tr></table></form><br><br><br><br>");
SHNotificationAdd(&stcNtData);
Sleep(15000);
SHNotificationRemove(&NOTIFICATION_GUID, 1);
return 0;
}
I'm offering beers now. No need to finish it, just give me some hints
Hi,
as I understand your article (http://www.krvarma.com/?p=146)
you need to create window, then assign it's HWND
to SHNOTIFICATIONDATA member HWND hwndSink;
then "The system will send WM_COMMAND with wParam set to 1000 to the hwndSink window." so - you need to handle WM_COMMAND in your window and check wParam - if it is equal to your parameter, then this message means "system sends you user choice from your html".
serfer222 said:
Hi,
as I understand your article (http://www.krvarma.com/?p=146)
you need to create window, then assign it's HWND
to SHNOTIFICATIONDATA member HWND hwndSink;
then "The system will send WM_COMMAND with wParam set to 1000 to the hwndSink window." so - you need to handle WM_COMMAND in your window and check wParam - if it is equal to your parameter, then this message means "system sends you user choice from your html".
Click to expand...
Click to collapse
Exactly as i understand it.
So I tried copying code from that article into my code but got stuck with really not understandable compiler errors. I think I need to find a good book explaining this message map.
The first thing I do not understand is that I only want to show the notification bubble (is working). If I create a windows handle (how?) will this overwrite the current screen (this is something I do not want).
window can be invisible.
I'm Win32 programmer, and I don't know exactly about WinCE.
If you are using VisualC++, I think you should use MFC, it's very easy to create window and then create message handler for this window.
search google for some
"WinCE c++ tutorial" and you will find how to create window and setup message loop. (add "Hello world" phrase to your search - this is usually used as very first example)
for example: http://www.codeproject.com/KB/mobile/ltwtdlg.aspx
serfer222 said:
window can be invisible.
I'm Win32 programmer, and I don't know exactly about WinCE.
If you are using VisualC++, I think you should use MFC, it's very easy to create window and then create message handler for this window.
search google for some
"WinCE c++ tutorial" and you will find how to create window and setup message loop. (add "Hello world" phrase to your search - this is usually used as very first example)
for example: http://www.codeproject.com/KB/mobile/ltwtdlg.aspx
Click to expand...
Click to collapse
Can you switch between MFC, ATL, etc. ? I know they are some kind of libraries but thought "don't look at it, there too much to learn/understand anyway ".
I've search but somehow you think there is the solution and then you learn the hard way, it's very old code. Will search further offcourse and I am reading a chapter on classes and if I can find; messages.
it's already very easy to handle messages without any MFC overload. Just check the uMsg parameter in your DefWindowProc. If you create a new Win32 project in Visual C++ wizard then you see what it's looking like. This is mandatory knowledge. Usually first thing you learn after Hello World. If you didn't know about message processing in Windows/Wince then it's the same like sitting in a car and don't know how to turn the keys.
Do you know how to open dsm file in textbox???
RAMMANN said:
it's already very easy to handle messages without any MFC overload. Just check the uMsg parameter in your DefWindowProc. If you create a new Win32 project in Visual C++ wizard then you see what it's looking like. This is mandatory knowledge. Usually first thing you learn after Hello World. If you didn't know about message processing in Windows/Wince then it's the same like sitting in a car and don't know how to turn the keys.
Click to expand...
Click to collapse
Thats how I feel exactly. It's strange. I read quickly thru 3 books about C++ and no mention of these messages. C#/Basic are easier to understand because of all the examples.
Found these:
- http://www.youtube.com/watch?v=kWVGqV2Yklw
- http://www.youtube.com/watch?v=cbe6yxBHEiU
The video does explain that the linked example doesn't look so different. What a lot of source code Ms creates for you..
If created a WIN32 smart device project and DefWindowsProc is only called when to pass the message to other programs. I need the windows handle for the notification and NOT display the window.
But again it's a bit to much for me at this moment. I haven't got a solution yet..Could somebody help me with not displaying this window. I would still like to use the windows handle to make sure I get the callbakcs to the WM_COMMAND.
Yes - I think you only need at end of WinMain before SHNotificationRemove
to add:
Code:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hacc, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Then a new function:
Code:
/* Redefine generic HANDLE_WM_ACTIVATE macro for Pocket PC */
#undef HANDLE_WM_ACTIVATE
#define HANDLE_WM_ACTIVATE(hwnd,wParam,lParam,fn) \
(SHHandleWMActivate((hwnd), (wParam), (lParam), &g_sai, 0), /*return*/ 0L)
/* Redefine generic HANDLE_WM_SETTINGCHANGE macro for Pocket PC */
#undef HANDLE_WM_SETTINGCHANGE
#define HANDLE_WM_SETTINGCHANGE(hwnd,wParam,lParam,fn) \
(SHHandleWMSettingChange((hwnd), (wParam), (lParam), &g_sai), /*return*/ 0L)
static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
HANDLE_MSG(hwnd, WM_CREATE, Main_OnCreate);
HANDLE_MSG(hwnd, WM_ACTIVATE, /* SHHandleWMActivate()*/ 0);
HANDLE_MSG(hwnd, WM_SETTINGCHANGE, /* SHHandleWMSettingChange() */ 0);
HANDLE_MSG(hwnd, WM_PAINT, Main_OnPaint);
HANDLE_MSG(hwnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hwnd, WM_DESTROY, Main_OnDestroy);
[B]// Remark: Here you can add more messages - also for what user has chosen.[/B]
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
and then the message handlers like this:
Code:
static BOOL Main_OnCreate(HWND hwnd, CREATESTRUCT *pcs)
{
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(mbi));
mbi.cbSize = sizeof(mbi);
mbi.hwndParent = hwnd;
mbi.nToolBarId = IDR_MNU_MAIN;
mbi.hInstRes = g_hInstance;
if (!SHCreateMenuBar(&mbi)) /* create the menu bar */
return FALSE;
g_hwndMB = mbi.hwndMB;
return TRUE;
}
But your Compiler should already make such a project by default and you can simple add the code fom _tmain to WinMain, which you've posted above.
Greetz
Micha
Thank you, yesterday I debugged and and debugged trying to understand how this works but the debugger doesn't stop always in all source code.
If f.i. you click on the screen I expected this to be an event, but the debugger didn't stop at all. Is there a command to always stop when a line of code is processed? Now it only stops when I have set a break point. I want to see every line processed...
I will try to implement your suggestions. For a newby it still looks difficult I hope someday I will look back to this and say "wow, that was so easy".
ajhvdb said:
Thank you, yesterday I debugged and and debugged trying to understand how this works but the debugger doesn't stop always in all source code.
If f.i. you click on the screen I expected this to be an event, but the debugger didn't stop at all. Is there a command to always stop when a line of code is processed? Now it only stops when I have set a break point. I want to see every line processed...
I will try to implement your suggestions. For a newby it still looks difficult I hope someday I will look back to this and say "wow, that was so easy".
Click to expand...
Click to collapse
Well, actually that's the reason why breakpoints exist. To stop the debugger and allow you look at the running code..... or what else did you think??
RAMMANN said:
Well, actually that's the reason why breakpoints exist. To stop the debugger and allow you look at the running code..... or what else did you think??
Click to expand...
Click to collapse
I want to say "stop and show at the current code line".
For example you start your program, goto the appropiate window, type in some data and NOW before you click on SAVE. You say to your debugger "catch this/coming event".
Debugger would stop if you'd handle this event and set break point to 1st command of this function.
then yo can go step by step through each line of code.
and hey: it's not soo easy,which I posted.But your Compiler (vs2008 or PellesC or whatever) would make this automatically for you and you only have to copy your part of code into WinMain of this automatic processed code.
The "Managers" then can help you also to add eventhandlers automatically.
you only have to set Breakpoints to the automatic processed Event-Handle-Function - them you can see,if this event is triggered like you want it.
You only think from the wrong direction
Ok, I learned a lot.
(The VS2008 debugger has bugs. If I set a breakpoint on line 100, and start debug, line 109 has the breakpoint. It looks like only the original code can be debugged)
I did start a new project and used the tips from above. I can catch a click on a link ahref field in the notification bubble.
I have disabled the screen so only the bubble is shown
Now I need to catch the menu button and more important the data in the html form (input type radio) in the notification bubble. For this I need to convert the param to a structure...!
I also need to extend the "while getmessage" loop with a timer. If 15 seconds have passed, I need to step out of the loop and quit automatically.
A lot of searching again.
BTW.
Thx all for helping me. Not really one tip did it, you all guided me a bit. If you think your tip helped me a lot then send me a PM with your paypal code. You can also send me your address/or your businessaddress. I will send you a small present/surprise related to my country (Holland).
in Germany we have a good cheese, too and the sense of a community like this great one,is for helping each other-especially beneath developers.
And it's always a question of finding out,how to manage something new
All the best for your further development.
Micha
Attached is the code of my subproject. I will update it if those last points are done. Hope it helps others.
If someone has a link or example code for those points. (or improvements of my code) please let me know.

[Q] [Resolved] [.Net CF 3.5] How do i create a treeview based file browser

I have a problem with a project i'm working on and that is:
How do i create a TreeView based file browser that can export a selected path and filename to a textbox and a Process.Start call at the same time. That's it in a nut shell. The main part if the tree view bit but i haven't figured out how to do variables yet and i'm gonna need one for the second part. I have spent hours googling and i have this question posted on a dedicated VB forum.
I'm using Visual Basic 2008 as the IDE and .Net CF 3.5 as the language (obviously)
If anyone has any ideas on this i'll gladly hear them coz i am really stuck. I found writting code to soft reset a device was easier
TreeNodeCollection tr=treeView1.Nodes;
TreeNode tn;
foreach (string dirs in System.IO.Directory.GetDirectories(System.IO.Directory.GetDirectoryRoot(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName)))
{
tn = new TreeNode(dirs);
//tr = new TreeNodeCollection();
tr.Add(tn);
}
ergintiravoglu said:
TreeNodeCollection tr=treeView1.Nodes;
TreeNode tn;
foreach (string dirs in System.IO.Directory.GetDirectories(System.IO.Directory.GetDirectoryRoot(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName)))
{
tn = new TreeNode(dirs);
//tr = new TreeNodeCollection();
tr.Add(tn);
}
Click to expand...
Click to collapse
Is that C# code or VB?
M3PH said:
Is that C# code or VB?
Click to expand...
Click to collapse
C#....VB don't have the curly brackets
So i've come back to this question after a few months avoiding VB. I'm now working on a new product and the lack of an folderbrowserdialog object in .Net CF is killing me.
What i need is this (oh and thanks to everyone that posted above but i can't make that solution work). A way to list all the folders on a device and then select one that can be passed to a variable so it's path can be used elsewhere. Maybe also pass the path to a textbox just so it's clear what you have selected. I've spent 2 days googling this and i did find a few things. Most don't work and the rest are in c# which is not much good. So if anyone wants to help me out i would really appreciate it.
Get your head round this.........
O.K. Here's how it's done, with a crash course in one of the most powerful of programming techniques - Recursion. It can confuse the hell out of rookie programmers, as they just can't get their heads round what's going on. It is dependant on a function's local variables and fortunately, .NET's stack based architecture allows us to use it to the full.
You will need, 1.) a TreeView object - named "treeView1" and 2.), a label named "label1" placed underneath it. The label is only there to prove the point that we can get at the full pathname of the selected directory in the Treeview. In reality it can be dropped, just put your processing code directly in the TreeView's AfterSelect() event.
The Form_Load() event gets the directories in the root directory, by calling GetDirList with an initial directory of "\".
GetDirList() adds the directories to the TreeView then calls GetDirList again on each directory to get any subdirectories, and again on each subdirectory, ad nauseum. Keep going until there are no more directories returned.
When completed TreeView contains a list of every directory/subdirectory on the device.
When you select an item from the TreeView the full pathname is displayed in the label. The image at the bottom shows it running under debug on the WinMo 5.0 emulator. There are several directories you would not normally see on your device.
Good Luck, stephj.
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Me.GetDirList("\")
End Sub
Private Sub GetDirList(ByVal PathName As String)
Dim dirs As String
For Each dirs In Directory.GetDirectories(PathName)
Dim tn As New TreeNode(dirs)
Me.treeView1.Nodes.Add(tn)
Me.GetDirList(tn.FullPath)
Next
End Sub
Private Sub treeView1_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs)
Me.label1.Text = e.Node.FullPath
End Sub
P.S.
You will need the VB equivalent of using System.IO adding to your project.
This stuff has been around since .NET CF 1.1
The original project was written in C#, I used .NET Reflector to translate it into VB from the original. The original C# is included here:-
Code:
using System;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
GetDirList("\\");
}
private void GetDirList(string PathName)
{
foreach (string dirs in System.IO.Directory.GetDirectories(PathName))
{
TreeNode tn = new TreeNode(dirs);
treeView1.Nodes.Add(tn);
GetDirList(tn.FullPath);
}
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
label1.Text = e.Node.FullPath;
}
}
}
cool thanks. I'll have a look at coding this tomorrow (i having some fun time right now).
I did have a look at doing this with a list box yesterday but i was getting errors left, right and centre so i really do appreciate the help.
Just an FYI the VB equivelent of "using" is "imports" otherwise most of the objects are the same but i don't nee to worry about adding it as the program is already interacting with the file system.
Again thanks very much. I really appreciate you taking the time to help me out.
I've just had a look at implementing this but i'm having trouble getting the treeview to populate with the folder list. What am i doing wrong? the object names all match up and i can't see why it's not working. Am i just being plain dense?
What i have Is pretty much what you posted except for a few changes to allow for the fact that the treeview object is in a tabcontrol and i already have a bunch of labels knocking around so the label is called label28 and not label1.
I'm sorry if it appears like i'm not trying or i'm asking you to do all the work but i am genuinely really stuck. I get the recursion principal, That's not an issue but i'm trying to create something from scratch that should really have been included in .net CF and i'm just not that good a programmer yet
Should work..... but without seeing the actual code it's rather hard to remotely debug it.
To prove the point, here's the complete VS2008 VB .NET CF 3.5 project.
In the \bin\release directory is the actual executable. If you have .NET CF 3.5 on your device, drop DirList.exe onto it and run it.
I had a look at the project you posted and just copied the coded over. I did make some tweaks so it only loaded the folder list when the tab the treeview was on was clicked but that didn't work so i repated the code in as is and voila! it works. Now all i need is to create a variable to store the selected path in but i think i can manage that.
Again a huge thanks.
Hierarchical view......
Here's the project to indent, compress, and expand the directory tree structure.
I was just playing around with this and i noticed that when you click on a directory below "\" the path becomes "\\this\path". This is obviously not a valid windows mobile path and it is causing an IOexception and I have no idea how to fix it. Google suggests lots of c# pages that say to use a regular expression to strip out the illegal characters but the example i found was for the entire path and it seemed to check each character against a variable of illegal values. I'm sure if that would work for me. Heres the link.
Let me know what you think.
I have no idea where the \\this is coming from, I can't replicate it.
To filter out the extra leading slash use this:-
Code:
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
If TreeView1.SelectedNode.FullPath.Length() = 1 Then
Label1.Text = TreeView1.SelectedNode.FullPath
Else
Label1.Text = TreeView1.SelectedNode.FullPath.Substring(1)
End If
Interesting new problem has cropped up with this code. It doesn't seem to work on rhodiums. It works fine in the emulator, my HD2 and all of CajunFlavouredBob's devices but i have a user that has a rhodium that get the error posted here. I can't replicte it and i don't have a rhodium to test it with. Any ideas?
Hmmmmm another tricky one. Without seeing the device actually throw the error, it can be a bit difficult.
Does this machine actually report the storage card as "\Storage Card"? Some machines don't. In which case you may have to use some storage card enumeration trick to get hold of the real name it uses. This may not apply in this case.
Also, to make things trickier still, the stack dump shows 'GetInternalDirectoryNames()' as the function throwing the error first. This is a level below your call of GetDirectories(), and is being used by the OS to actually go get the info. You may have to create a test version of EXCT2 full of Try...Catch programming blocks, to try to get to the real point where the error is being thrown.
well this turned out to be a memory related issue. So instead of using the folder browser we now use the stock winmo savedialog. because it uses less memory and allows us access to the locations we need.
Thanks for helping though steph.

Categories

Resources