|
Relative to what? When using the IO classes files are already relative to the application's - not the library in which your code runs - current working directory, not necessary the application's installation directory. You can get the current working directory by getting Environment.CurrentDirectory and the application's installation directory by getting Application.ExecutablePath , passing that to Directory.GetParent .
Depending on what installation technology you're using you can also get the exact path to any file regardless of what type it is. Since you didn't provide any details about what you're trying to do, however, it's impossible to help you.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi! Try this:
private string m_strFileName = ".\\account.xml";
----------------------
Seeing the infinite...
|
|
|
|
|
I have a problem with this code:
------------------------------------------------------------
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct StructA
{
public int MyVariable;
}
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct StructB
{
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 3)]
public StructA[] MyArray; // size must be 3;
}
------------------------------------------------------------
If I take Marshal.SizeOf(StructB) I have this error: Type can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed. So, what can I do to fix the problem?
|
|
|
|
|
There are limitations to marshaling C-style structs in managed code. See Interop Marshaling[^] for details.
You can unroll your structure (or "flatten" it) to make a new structure. This is typically preferred over marshaling structs within structs (which is not supported at all on .NET CF).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heyas all,
I'm kind of confused on this myself, so I'll attempt to explain the best I can, so bare with me
I'm making a cataloging program that reads data from an xml file. The xml file has to obvisiously have a specific format, or at least specific tags to look for to load the correct data into the controls on the windows form. I'm thinking that XmlDocument is the best way to go so I have
<br />
public class XmlData<br />
{<br />
public int CheckForData(string filename)<br />
{<br />
if(!File.Exists(filename))<br />
{<br />
XmlDocument Xdoc = new XmlDocument(nameTable);<br />
}<br />
}<br />
}<br />
This brings up more issues. First and foremost, how do I go about using a NameTable? The user needs to be able to name their file anything, so how do I go about ensuring that the last file used is loaded the next time the program starts, and also, if a file hasn't been previously used, that a new default file is loaded. I've created and added a skeleton xml file that I want the program to use to the project called BlahData.xml. Am I on the right track in anything I'm doing or thinking?
ANY INFORMATION even remotely related to what I'm attempting to accomplish will be most appreciated.
Thanks all,
John
|
|
|
|
|
Hi,
Ill try to break up your requests to little answerable parts :
1. I see no need for you to specify a NameTable for your XmlDocument. Just use the parameterless constructor, when working with XmlDocument.
2. To load the last file used in the next session you will have to store this information somewhere. As I think this wont be the last setting you need to store in your program I would create a configuration file in xml format where you can store any type of information. You could search CodeProject for this part. If I remember right there is at least one implementation around which should make this point easy.
3. To create a skeleton of your xml was no bad idea. Depending on the complexity of its structure you could also create it programmatically, but having a template makes it simpler. You can add the file directly to your assembly as an embedded resource and save it to your desired location with the following code:
<br />
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();<br />
<br />
Stream inputStream = assembly.GetManifestResourceStream("DefaultNameSpaceOfTheProject.FileNameOfTheEmbeddedResource");<br />
FileStream outputStream = new FileStream(newFilePath, FileMode.CreateNew);<br />
byte[] buffer = new byte[1024];<br />
while (true) <br />
{<br />
int read = inputStream.Read(buffer, 0, buffer.Length); <br />
outputStream.Write(buffer, 0, read);<br />
if (read < 1024)<br />
break;<br />
}<br />
outputStream.Close();<br />
inputStream.Close();<br />
This will assure that noone changes your default file once the program is installed.
|
|
|
|
|
Is there a tool that can convert rtf to html? The setup is this, the rtf text will be coming from the DB. The conversion will happen on the server, so i don't have access to the file system; so Word SaveAsHTML won't work.
OK, does someone know of anything?
|
|
|
|
|
A quick search[^] on "rtf to html" yields many, many results and this has been covered many times on this site. Click "Search comments" at the top of this message board to search for additional comments.
Actually you can use Word because Word does not have to load from a persistent file, but can also load from a stream. This is because the Word.Document object implements IPersistStorage (a COM interface) which loads an IStorage object, which you can obtain from P/Invoking OleCreateFromData . This requires interop'ing many native interfaces, like those I mentioned above as well as IDataObject (which is different from .NET's implementation of IDataObject , though they represent the same thing). A good understand of Interoperating with Unmanaged Code[^] is required, and knowledge of COM is very helpful.
This is still not the greatest idea, however, since the Word automation server is not scalable and should typically not be used on the backend of a client/server application.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Since the Word automation server should not be used in the backend of a server application, is there any recomended way of converting Word docs to other formats in a server environment? My app requires uploading documents and manipulating those documents; so supporting a Word format would be very convenient for my users.
Thanks,
Andy
|
|
|
|
|
That's exactly the sort of situation that the Word 2003 XML Schema[^] solves. Your users upload Word 2003 documents saved as XML (and you can automate this using solution files) and you work with pure and rich XML. Send the modified (or original) version back with the right content-type and it works just like an actual document in every way.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
i'm making a 2d sprite game with directx but i can't figure out how to use the alpha channel so that parts of my images are transparent. what is the best type of image to use, .png, .bmp? and how do i apply an alpha channel to them.
thanks,
Rob Tomson
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
.bmp does not support alpha channels, nor does .jpg, .gif, or .tiff. .gif only supports an indexed color to serve as a transparency, which is the same as what is done for 24-bit and lower .ico files. .png does support alpha channels. You can find lots of information about image formats by searching the web, but this forum is not the appropriate place for questions not related to using C#. You can also use Image.IsAlphaPixelFormat on each member of the PixelFormat enumeration to see which ones that GDI+ (which .NET uses for the graphics classes) supports support alpha channels.
If you're question is about how to use such images in C# then see the Image class in the .NET Framework SDK. Managed DirectX can also make use of these, as well as native code. Use Bitmap.GetHbitmap to get an IntPtr that represents the HBITMAP (native handle to a bitmap data structure, which describes about any image format) for calls to native APIs that require an HBITMAP .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I am trying to build a general purpose math and graphics class library, but am running into problems because it seems that you can't use graphics classes in a class library unless the library is control-based. But I don't want a control, just some classes and methods for mathematical and graphical calculations. Does anyone out there know how to do this?
Thanks,
Royce
|
|
|
|
|
|
Of course u can, but the class library template does not reference the System.Drawing assembly. U'll have to add that reference manually.
|
|
|
|
|
first let me explain my situation, my room mate and i both have computers and often enough there's something one of us wants to show the other on our screen but we're to lazy to get up and go look. so this is what i would like to do: i would like to grab a window, like internet explorer, and drag it to his desktop so that he can now see the page. or just send the current screen display to his computer.
thanks,
Rob Tomson
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
|
You want to program this yourself?!?
Use VNC. Messing around with it in a private network is really funny.
|
|
|
|
|
How to get that any Arrow key is pressed.
|
|
|
|
|
Override the KeyPress, KeyDown, or KeyUp event (as you need) in your form class, and check the KeyValue values of KeyEventArgs.
Peter Molnar
|
|
|
|
|
I m sorry are you asking me to use in Key down event
<br />
if(e.KeyValue == Keys.Down)
i have tried every mathod that i know to get ArrowKeys but not able to do so. Please help me.
|
|
|
|
|
Ok Problem Solved. For others Info how i able to do this
<code
protected override="" bool="" processcmdkey(ref="" message="" msg,="" keys="" keydata)
="" {
="" switch(keydata)
="" case="" keys.down:="" label1.text="Hello" ;
="" break;="" and="" for="" other=""
="" }
="" return="" base.processcmdkey="" (ref="" keydata);
="" }
}
<="" code="">
havn't find any other mathod so if you know any other mathod i really would like to read. Thanks in advance
|
|
|
|
|
you should cast the Keys enum to int, so it will compile
private void OnKeyPress(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyValue == (int)Keys.Down)
{
...
}
}
Peter Molnar
|
|
|
|
|
Hey all,
I'm getting a strange "Index (zero based) must be greater than or equal to zero and less than the size of the argument list" exception thrown when I trigger an event (atleast that's where I've tracked the problem to). This seems very strange to me since I'm doing no idexing here. I'm making a WebRequest, retrieving an XML document and parsing / serializing it to an object, then triggering an event to notify my Window.Form app that the data is available for display, however when I call my event passing it my custom EventArgs class I get the above exception.
I've played around a bit passing my EventArgs class different things and if I pass it a null (ie don't populate any of the data within it through a default cuonstructor the exception doesn't occur (this is of course useless to me caus I need the app to get this data). I've pretty much run out of ideas here ... could this be a known bug and I'm just late to the game? Has anyone else run into this? Am I missing something obvious (though this case is embarasing it's usually easily fixed).
I'm not sure posting any code will be very descriptive because it's distributed over so many classes, but some snipits follow:
// Delegate
public delegate void CMNMatchDetailsEventHandler(object sender,
MatchDetailsEventArgs a);
// EventArgs holding needed class
public class MatchDetailsEventArgs : EventArgs
{
public MatchDetails Response;
public MatchDetailsEventArgs(MatchDetails r)
{
Response = r;
}
}
.
.
// getting XML doc from web and serializing (using inherited method from an abstract class)
MatchDetails resp =
(MatchDetails)ExecuteGET(url, typeof(MatchDetails));
// calling event :: Passing my populated class to the EventArgs for my front end app.
MDetails(this, new MatchDetailsEventArgs(resp));
If I replace the "resp" class/parameter with null the exception does not occur, though the "resp" class contents are fully populated (I've dumped it to the console both before serializing the XML and after, everything appears to be intact)
I'm at a loss here.
Any help would be awesome.
Thanks in advance
- flip
|
|
|
|
|
Im over 90% sure that the class handling the event is raising the error. To track down the error source you should enclose the part where you trigger the event with a try catch block and look at the stack trace of the catched exception:
<br />
try {<br />
MDetails(this, new MatchDetailsEventArgs(resp));<br />
} catch (Exception exc) {<br />
Console.WriteLine(exc.StackTrace);<br />
}<br />
From the given output you will exactly get the source of the error.
|
|
|
|