|
nice article but Can i do it through managed code? that is in c# ..?? even its Okei if i hav to read from registry. Where i can get these info ?
Thanks for help.
|
|
|
|
|
Well, you could always wrap the unmanaged code in a C++/CLI class and use it from C#.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
It does not work because it just reads from sys parameter. It gives me info about where i am currently executing not about what all versions are installeed
|
|
|
|
|
i need a complete example on RowFilter property of DataView Object in C#
|
|
|
|
|
|
how can i use RowFilter property of DataView object in C# to search a specific row?
|
|
|
|
|
Hi all,
I'm relatively new to C# and now i would like to have the best of both worlds, Java and C#. I would like to know how is it possible for a Java program to call a function, for e.g. helloWorld() in a c# program.
Appreciate any simple examples or links to demonstrate the use.
Thanks
|
|
|
|
|
ahjiang wrote: is it possible for a Java program to call a function, for e.g. helloWorld() in a c# program?
No.
Currently Java just support to call C/C++ native function through JNI(Java Native Interface). See this[^].
regards,
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
I think you are in the wrong forum. Try to post your question in Java Forum. Because the code what you want is a java code.
|
|
|
|
|
I have a c++ code including a method as
parsefile( FILE * pfile);
I have exported this method in c++ in a dll. But In my c# code I want to use this method.
Thus, I have written the below code in the cs file.
[DllImport("main.dll")]
public extern static void parseFile( File pfiOriginal );
static void Main(string[] args)
{
/**** I don't know how to handle FILE * here because there is no FILE *
in c#. deneme.pqd is my file to be used by parsefile method.The
compiler gives error that File constructor takes no arguments.
*****/
File a = new File("deneme.pqd");
parseFile(a);
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
Please can you help me urgently about a method doing this.
|
|
|
|
|
I think the structure FILE and class File is complete different.
If you have a structure called FILE, then copy it to C#.
struct FILE
{
...
}
then try to use this code:
[DllImport("main.dll")]
public extern static void parseFile([MarshalAs(UnmanagedType.Struct)]FILE pfiOriginal );
|
|
|
|
|
I have no structure called FILE. It is a C File I/O. So it is a a FILE pointer such as FILE *fp.
What should I do then????
|
|
|
|
|
Just use the C# function to open file.
FileStream fileStream = new FileStream("myfile.bin", FileMode.Open);
BinaryReader binaryReader = new BinaryReader(fileStream);
int a = binaryReader.ReadInt32();
float b = binaryReader.ReadSingle();
...
binaryReader.Close();
fileStream.Close();
I'm not a fan of DLLImport. It is not so easy. It is easier to write the function again in C#.
|
|
|
|
|
But I have to use Dllimport (((
|
|
|
|
|
Try using IntPtr:
[DllImport("testcpp2.dll"]
private static extern void parseFile(IntPtr pFile);
using(FileStream fStream = new FileStream("test.bin", FileMode.Open))
{
parseFile(fStream.Handle);
}
and if it still not working, try to write a extra function for bridging between parseFile(FILE* file) and parseFile(string filename).
Something like this:
void parseFileWithFilename(string filename)
{
}
Then in C# you can give only the filename in string. It is easier.
|
|
|
|
|
by Luking @ the funtion name, i concluded that you are trying to parse the file. for that you can write your own funtion in C# right? Lot of samples are there in google.
|
|
|
|
|
dear friends,
please send me code to create a program which can display dynamic IP's of all the running client.
regards.
Pawan Mishra
MCA, MCP.NET, MCAD.NET
|
|
|
|
|
Is this the same question as in your thread in the .NET Framework board?
---
b { font-weight: normal; }
|
|
|
|
|
How do I create a DataSet from an XSD file. I’ve read about some “Generate DataSet” option in Visual Studio but I cant find it.
Does it exist external tools for this too?
_____________________________
...and justice for all
APe
|
|
|
|
|
See if this helps..
http://hacks.oreilly.com/pub/h/5157
http://aspnet.4guysfromrolla.com/articles/020806-1.aspx
|
|
|
|
|
hi,
Does anybody know where to get C# source code to create the fancy Office 2007 Toolbar Ribbon with the big round button?
|
|
|
|
|
I want to use the <include> XML directive to drag in how to use doumentation in to my code so that it ends up in in the Object Browser and Intellisense. I've had no problems doing that, but there is one thing that concerns me. I put the XML in an existing XML file, that already has XML data that's needed by the designer class. The XML <include> directive requires that I specify a file path, is there some way I can symbolise the file path -ideally I'd like to use the resource name <namespace>.<classname>.Resources.XMLData.
|
|
|
|
|
I have seen the guidelines(Code project - before 2 days) to export the data from datagrid to excel sheet in Web application. How to make up the same operation in windows application.
Jey
|
|
|
|
|
You can use the csv concept.
SqlConnection cn ;
SqlCommand cmd ;
string filename ;
SqlDataReader dr ;
System.Text.StringBuilder sb ;
private void Button1_Click(object sender, System.EventArgs e)
{
cn=newSqlConnection("server=localhost;uid=sa;pwd=;database=northwind");
filename = "products.csv";
cmd = new SqlCommand("select * from products ", cn);
cmd.Connection.Open();
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
sb = new System.Text.StringBuilder();
//For field Names
for(int i = 0 ;i< = dr.FieldCount - 1;i++)
{
if( i < (dr.FieldCount - 1) )
{
sb.Append("\t" + dr.GetName(i) + "\t" + ",");
}
else
{
sb.Append("\t" + dr.GetName(i) + "\t" + "\n");
}
}
//For field Values
while( dr.Read())
{
for(int i = 0 ;i<= dr.FieldCount - 1;i++)
{
if( i < (dr.FieldCount - 1) )
{
sb.Append("\t" + dr.GetValue(i) + "\t" + ",");
}
else
{
sb.Append("\t" + dr.GetValue(i) + "\t" + "\n");
}
}
}
dr.Close();
cn.Close();
Response.ContentType = "Application/x-msexcel";
Response.AddHeader ("content-disposition", "attachment; filename=" + filename ) ;
//Write the file directly to the HTTP output stream.
Response.Write(sb.ToString());
Response.End();
}
/****************************************************************************
private void btExport_Click(object sender, EventArgs e)
{
string strTemp = String.Empty;
dst = new DataSet();
dst.Tables.Add("UserTable");
string strConnection = "Data Source=QUEST03;Initial Catalog=UserDatabase;User ID=hari; Password=shriji;";
SqlConnection conn = new SqlConnection(strConnection);
conn.Open();
SqlCommand cmd = new SqlCommand("Select * From UserTable",conn);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
using (StreamWriter sw = new StreamWriter("E:/Hari/Problem_Import_Export/Problem1/test.csv"))
{
for (int i = 0; i <= dr.FieldCount - 1; i++)
{
if (i < (dr.FieldCount - 1))
{
sb.Append("\t" + dr.GetName(i) + "\t" + ",");
strTemp = strTemp + "\t" + dr.GetName(i) + "\t" + ",";
}
else
{
sb.Append("\t" + dr.GetName(i) + "\t" + "\n");
strTemp = strTemp + "\t" + dr.GetName(i) + "\t" + "\n";
}
}
sw.WriteLine(strTemp);
//For field Values
strTemp = String.Empty;
while (dr.Read())
{
for (int i = 0; i <= dr.FieldCount - 1; i++)
{
if (i < (dr.FieldCount - 1))
{
sb.Append("\t" + dr.GetValue(i) + "\t" + ",");
strTemp = strTemp + "\t" + dr.GetValue(i) + "\t" + ",";
}
else
{
sb.Append("\t" + dr.GetValue(i) + "\t" + "\n");
strTemp = strTemp + "\t" + dr.GetValue(i) + "\t" + "\n";
}
}
sw.WriteLine(strTemp);
}
}
dr.Close();
conn.Close();
MessageBox.Show("Data Is Imported Successfully...Test.txt File is Created.");
}
|
|
|
|
|
using System;
using System.IO;
using System.Data;
using System.Windows.Forms;
namespace AzoControls.MyDataExport
{
public class AzoDataExportToXLS
{
private int rowCount = 0;
private int sheetCount = 1;
private System.IO.StreamWriter excelDoc;
const string endExcelXML = "";
const string startExcelXML = "<xml version="">\r\n<workbook "="" +
="" "xmlns="\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n"" xmlns ="\"urn:schemas-microsoft-com:office:office\"\r\n" "xmlns:x="\"urn:schemas-" microsoft-com:office:"="" "excel\"\r\n="" xmlns:ss="\"urn:schemas-microsoft-com:"" "office:spreadsheet\"="">\r\n <styles>\r\n " +
"\r\n " +
"<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" +
"\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" +
"\r\n <Protection/>\r\n \r\n " +
"\r\n <Font " +
"x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n \r\n " +
"\r\n <NumberFormat" +
" ss:Format=\"@\"/>\r\n \r\n \r\n <NumberFormat " +
"ss:Format=\"0.00\"/>\r\n \r\n " +
"\r\n <NumberFormat " +
"ss:Format=\"0\"/>\r\n \r\n \r\n <NumberFormat " +
"ss:Format=\"dd/mm/yyyy;@\"/>\r\n \r\n " +
"\r\n ";
private DataTable dtXLS;
private DataRow drXLS;
public AzoDataExportToXLS(DataTable parTableName)
{
//Parameter DataTable Object
this.dtXLS = parTableName;
}
public void ExportToXLS()
{
try
{
string strFileName = "File001";
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.InitialDirectory = Path.GetDirectoryName(strFileName);
saveDlg.FileName = Path.GetFileNameWithoutExtension(strFileName);
saveDlg.AddExtension = true;
saveDlg.Filter = "Windows Excel (*.xls)|*.xls";
if (saveDlg.ShowDialog() == DialogResult.OK)
{
try
{
this.exportToExcel(saveDlg.FileName.ToString());
//this.WriteDataToXLS(saveDlg.FileName.ToString());
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
return;
}
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
}
private void exportToExcel(string fileName)
{
excelDoc = new System.IO.StreamWriter(fileName);
excelDoc.Write(startExcelXML);
excelDoc.Write("<worksheet ss:name="\"DataPages"" +="" sheetcount.tostring().trim()="" "\"="">");
excelDoc.Write("");
excelDoc.Write("<row>");
for (int ic = 0; ic <= dtXLS.Columns.Count-1; ic++)
{
excelDoc.Write("<cell ss:styleid="\"BoldColumn\"">");
excelDoc.Write(dtXLS.Columns[ic].Caption.ToString());
excelDoc.Write("");
}
excelDoc.Write("");
for (int x = 0; x <= dtXLS.Rows.Count-1; x++)
{
rowCount++;
drXLS = dtXLS.Rows[x];
//if row > 64000 new page
if (rowCount == 64000)
{
rowCount = 0;
sheetCount++;
excelDoc.Write("");
excelDoc.Write(" ");
excelDoc.Write("<worksheet ss:name="\"Sheet"" +="" sheetcount="" "\"="">");
excelDoc.Write("");
}
excelDoc.Write("<row>"); //ID=" + rowCount + "
for (int y = 0; y < this.dtXLS.Columns.Count; y++)
{
System.Type cellType;
cellType = drXLS[y].GetType();
switch (cellType.ToString())
{
case "System.String":
string XLSParameter = drXLS[y].ToString();
XLSParameter = XLSParameter.Trim();
XLSParameter = XLSParameter.Replace("&", "&");
XLSParameter = XLSParameter.Replace(">", ">");
XLSParameter = XLSParameter.Replace("<", "<");
excelDoc.Write("<cell ss:styleid="\"StringLiteral\"">" +
"");
excelDoc.Write(XLSParameter);
excelDoc.Write("");
break;
case "System.DateTime":
DateTime XMLDate = (DateTime)drXLS[y];
string XMLDatetoString = ""; //Excel Converted Date
XMLDatetoString = XMLDate.Year.ToString() +
"-" +
(XMLDate.Month < 10 ? "0" +
XMLDate.Month.ToString() : XMLDate.Month.ToString()) +
"-" +
(XMLDate.Day < 10 ? "0" +
XMLDate.Day.ToString() : XMLDate.Day.ToString()) +
"T" +
(XMLDate.Hour < 10 ? "0" +
XMLDate.Hour.ToString() : XMLDate.Hour.ToString()) +
":" +
(XMLDate.Minute < 10 ? "0" +
XMLDate.Minute.ToString() : XMLDate.Minute.ToString()) +
":" +
(XMLDate.Second < 10 ? "0" +
XMLDate.Second.ToString() : XMLDate.Second.ToString()) +
".000";
excelDoc.Write("<cell ss:styleid="\"DateLiteral\"">" +
"");
excelDoc.Write(XMLDatetoString);
excelDoc.Write("");
break;
case "System.Boolean":
excelDoc.Write("<cell ss:styleid="\"StringLiteral\"">" +
"");
excelDoc.Write(drXLS[y].ToString());
excelDoc.Write("");
break;
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.Byte":
excelDoc.Write("<cell ss:styleid="\"Integer\"">" +
"");
excelDoc.Write(drXLS[y].ToString());
excelDoc.Write("");
break;
case "System.Decimal":
excelDoc.Write("<cell ss:styleid="\"Decimal\"">" +
"");
excelDoc.Write(drXLS[y].ToString());
excelDoc.Write("");
break;
case "System.Double":
excelDoc.Write("<cell ss:styleid="\"Decimal\"">" +
"");
excelDoc.Write(drXLS[y].ToString());
excelDoc.Write("");
break;
case "System.DBNull":
excelDoc.Write("<cell ss:styleid="\"StringLiteral\"">" +
"");
excelDoc.Write("");
excelDoc.Write("");
break;
default:
throw (new Exception(cellType.ToString() + " not handled."));
}
}
excelDoc.Write("");
}
excelDoc.Write("");
excelDoc.Write(" ");
excelDoc.Write(endExcelXML);
excelDoc.Close();
}
}
}
grandy
|
|
|
|