|
Hi! sorry for my late reply.
Thanx for your help but I have a few questions.
What type is the Worksheet?
I have an object of type Word.ApplicationClass.
But I can't find the worksheet.
Won't your range be from the first cell to your last cell?
I mean if you write it like this:
range = Worksheet.get_Range(Worksheet.Cells[1, 1], Worksheet.Cells[2, 2]);
Will the range then only contain 2 cells or every cell between the cells?
Thanx!
|
|
|
|
|
worksheet is an item of excel.
Word.Cell mergeBeginCell = wordTable.Cells(1, 2);
Word.Cell mergeEndCell = wordTable.Cell(2, 2);
mergeBeginCell.Merge(mergeEndCell);
|
|
|
|
|
Hi there,
Is there anyway that I can print the html file from commandline without showing print dialog?
I tried ShellExecuteEx and it does nothing.
Thank you.
|
|
|
|
|
Have you looked at PrintDocument?
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref8/html/T_System_Drawing_Printing_PrintDocument.htm
Example:
class Program
{
static Font printFont = new Font("Arial", 10);
static void Main(string[] args)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
doc.Print();
}
static void doc_PrintPage(object sender, PrintPageEventArgs e)
{
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
float yPos = topMargin + (printFont.GetHeight(e.Graphics));
e.Graphics.DrawString("Hello", printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
e.HasMorePages = false;
}
}
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hello,
I've derived Stream class to receive an internet audio stream.
But the DirectSound class can't play this because of the missing length and position informations.
But I don't have this, because the stream has no end!
How can I solve this?
|
|
|
|
|
Freak.2k wrote: I've derived Stream class to receive an internet audio stream.
But the DirectSound class can't play this because of the missing length and position informations.
But I don't have this, because the stream has no end!
1) Create a SecondaryBuffer object.
2) Set the length to some amount, say 8192, for example.
3) Create two arrays, each with a length half as long as the length of the SecondaryBuffer .
4) Initialize the buffer with Notify objects to notify you when the buffer reaches position 0 and half the length of the buffer.
5) Read data from your stream and place it into the first array.
6) Write the array data to the SecondaryBuffer .
7) Play the SecondaryBuffer with the looping option.
8) As you get notified by the SecondaryBuffer read another array from your stream and write it to the buffer.
This should work ok as long as your stream is staying ahead of your buffer, no guarrantees since this is an internet audio stream, so you may want to make the arrays large enough to give the internet stream a good head start. And be prepared to handle the situation when there are no bytes yet available from your stream.
Hope this helps.
|
|
|
|
|
Hello everyone,
I have an Array which holds list of items. Some of the items in the list are repeated (Undesirable).
Can someone tell me how I can remove/rearange/rebuilt the array without the repeated items?
Thank you very much and have a great weekend.
Khoramdin
|
|
|
|
|
Just off the top of my head... this seems good, it's O(n)
<font>public datatype[] UnduplicateArray(datatype[] startarray)
{
List<datatype> endarray = new List<datatype>();
foreach (datatype d in startarray)
if (!endarray.Contains(d))
endarray.Add(d);
return endarray.ToArray();
}
</datatype></datatype></font>
Last modified: 1hr 31mins after originally posted --
|
|
|
|
|
eggsovereasy wrote: this seems good, it's O(n)
Are you sure?
The List.Contains method loops throught each item in the collection looking for an existing item. That doesn't seem very good...
I would rather use a Dictionary, as that uses a hash table, which is much faster when looking for an existing item.
---
single minded; short sighted; long gone;
|
|
|
|
|
You are absolutely correct, I didn't consider what Contains() was doing, so its probably more like O(n^2).
|
|
|
|
|
I've got a .NET 2 generic library that does operations on any kind of list. I have a Distinct method in that library that returns only the unique elements in the list. It looks something like:
public static IEnumerable<T> Distinct<T>(IEnumerable<T> items)
{
Queue<T> distinct = new Queue<T>();
foreach (T element in items)
{
if (!distinct.Contains(element))
{
distinct.Enqueue(element);
}
}
return distinct;
}
Then you can use it like this:
string[] myStrings = { "hello", "world", "hello" };
IEnumerable<string> distinct = Distinct(myStrings);
|
|
|
|
|
This is more flexible than my example, but its the same logic. I would use this were I the OP.
|
|
|
|
|
Considering that you are taking in and returning IEnumerable<t>, wouldn't it be better to use yield return, instead of returning the distinct elements in one shot? That way, it fits in well with the "lazy" evaluation semantics of IEnumerable<t> (like when items actually enumerates over the contents of a file, for example). Something like
public static IEnumerable<T> Distinct<T>(IEnumerable<T> items)
{
Queue<T> distinct = new Queue<T>();
foreach (T element in items)
{
if (!distinct.Contains(element))
{
distinct.Enqueue(element);
yield return element;
}
}
}
If the caller stops with the first two distinct elements, for example, then this saves a lot of needless computation.
|
|
|
|
|
Yes, good catch, Senthil. I'm a big fan of yield return -- I'm surprised I didn't catch it myself. Thanks.
|
|
|
|
|
Hi,
I am getting weird error while trying to check whether this xml document is well form or not.
Error I am getting is only for the xml file who has external dtd defined. If xml file requires a schema or inline dtd... it works perfectly fine. I tested this xml file with Stylus Studio Xml Editor and it works perfectly fine and validates the MessageExternalDTD.xml file. In my case the error it says is "Could not find file 'C:\Documents and Settings\ronak.patel\Local Settings\Temp\message.dtd'. Even though dtd file is at the same location as the xml file is.
One thing i understand from this error during validating or checking wellformness xml file requires dtd or xsd files to be present at "C:\Documents and Settings\ronak.patel\Local Settings\Temp\" directory. If they are there and not in the same directory where xml file is still it would work, but not vice versa.
MessageExternalDTD.xml
<message>
<to>Dave
<from>Susan
<subject>Reminder
<text>Don't forget to buy milk on the way home!
message.dtd
Here is my Code...
XmlDocument xmlDocument = xmlData.xmlDocument;
//xmlDocument is already given to me..
MemoryStream mstream = new MemoryStream();
StreamWriter writer = new StreamWriter(mstream);
xmlDocument.Save(mstream);
mstream.Seek(0, SeekOrigin.Begin);
try
{
while (reader.Read())
{
}
}
catch (XmlException ex)
{
MessageBox("XML Error : " + ex.Message);
m_success = false;
}
catch (Exception exe)
{
MessageBox("Error : " + exe.Message);
m_success = false;
}
finally
{
if (!m_success)
{
MessageBox.Show("Not Well Form");
}
else
{
MessageBox.Show("Well Form");
}
m_success = true;
reader.close();
}
|
|
|
|
|
Hi,
Can any one give me example of site where i can use
WebClient.DownloadFile(url,localfile); with Credentials...supplied to Webclient
like this
NetworkCredential auth = new NetworkCredential(tbUsername.Text, tbpassword.Text);
client.Credentials = auth;
I tried with so many sites but still no luck. Basically i want to download file from a website which asks for user credentials which i can pass to WebClient object.
|
|
|
|
|
Hi,
I am doing Http Get and Post operation using WebClient class of System.Net.
Is there a way to block cookies while i am doing this operations?
|
|
|
|
|
Hi,
I have working code of above function in vc++. I need help to convert it to c#....Any one know how to achieve this in c# please help me out here.
The code i got is from this link....
http://www.codeproject.com/dll/Execute_DLL_Function.asp
bool GetDLLFileExports(char *szFileName, unsigned int *nNoOfExports, char **&pszFunctions)
{
HANDLE hFile;
HANDLE hFileMapping;
LPVOID lpFileBase;
PIMAGE_DOS_HEADER pImg_DOS_Header;
PIMAGE_NT_HEADERS pImg_NT_Header;
PIMAGE_EXPORT_DIRECTORY pImg_Export_Dir;
hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile == INVALID_HANDLE_VALUE)
return false;
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if(hFileMapping == 0)
{
CloseHandle(hFile);
return false;
}
lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
if(lpFileBase == 0)
{
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_DOS_Header = (PIMAGE_DOS_HEADER)lpFileBase;
pImg_NT_Header = (PIMAGE_NT_HEADERS)((LONG)pImg_DOS_Header + (LONG)pImg_DOS_Header->e_lfanew);
if(IsBadReadPtr(pImg_NT_Header, sizeof(IMAGE_NT_HEADERS))||pImg_NT_Header->Signature != IMAGE_NT_SIGNATURE)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_Export_Dir = (PIMAGE_EXPORT_DIRECTORY)pImg_NT_Header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if(!pImg_Export_Dir)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_Export_Dir= (PIMAGE_EXPORT_DIRECTORY)ImageRvaToVa(pImg_NT_Header,pImg_DOS_Header, (DWORD)pImg_Export_Dir, 0);
DWORD **ppdwNames = (DWORD **)pImg_Export_Dir->AddressOfNames;
ppdwNames = (PDWORD*)ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header, (DWORD)ppdwNames, 0);
if(!ppdwNames)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
*nNoOfExports = pImg_Export_Dir->NumberOfNames;
pszFunctions = new char*[*nNoOfExports];
for(unsigned i=0; i < *nNoOfExports; i++)
{
char *szFunc=(PSTR)ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header, (DWORD)*ppdwNames, 0);
pszFunctionsIdea = new char[strlen(szFunc)+1];
strcpy(pszFunctionsIdea,szFunc);
ppdwNames++;
}
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return true;
};
|
|
|
|
|
I'm rewriting a project from C++(MFC) to C#, mostly to learn this new language. In that project I use CAsyncSocket to create a TCP connection with another peer in a network to send some notification messages or some very small amount of data or a requests.
I tried to find a similar easy way to implement an asynchronous TCP connection in C#, but most of them are not.
Is there any alternative to that in C#? Is there any component or namespace or class that can help me do it quickly?
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
System.Net.Socket namespace?
only two letters away from being an asset
|
|
|
|
|
Thanks Mark.
Mark Nischalke wrote: only two letters away from being an asset
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
System.Net.Sockets namespace is what you want if you still want to use sockets.
.NET has a nice abstraction over sockets called Remoting. With remoting, instead of sending bytes over the pipe, you connect to a .NET object on the other end and call functions on it like a regular object. If you're interesting in .NET remoting, check out the System.Runtime.Remoting namespace, as well as the System.Runtime.Remoting.dll in the .NET framework.
Finally, the new "cool" way of cross-process communication is WCF (Windows Communication Foundation). It's new in .NET 3 and provides a messaging-based, loosely-coupled, service architecture. There are articles here at CP as well as articles around the net on how to use WCF.
|
|
|
|
|
Judah Himango wrote: System.Net.Sockets namespace is what you want if you still want to use sockets.
Ireally prefer not to do it that way. It needs a lot of works, I think.
Remoting and WCF.
Thanks alot judah.
I'm going to check them right now.
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
Is there a way to use Socks4, Socks4a or Socks5 proxy types with WebProxy class.
I have downloaded a Proxy Server "ccproxy" from
http://www.youngzsoft.net/ccproxy/screenshot.htm
where i can use my code to download and upload files but it works only with Port 808 reserved for HTTP proxy in ccproxy server.
Http Get Code...
WebClient client = new WebClient();
if (tbpassword.Text != "" && tbUsername.Text != "")
{
NetworkCredential auth = new NetworkCredential(tbUsername.Text, tbpassword.Text);
client.Credentials = auth;
}
if (tbProxyAddress.Text != "" && tbProxyPort.Text != "")
{
WebProxy proxy = new WebProxy(tbProxyAddress.Text, Convert.ToInt32(tbProxyPort.Text));
if(tbProxyUsr.Text != "" && tbProxyPwd.Text != "")
proxy.Credentials = new NetworkCredential(tbProxyUsr.Text, tbProxyPwd.Text);
client.Proxy = proxy;
}
Uri uri = new Uri(tbURL.Text);
client.DownloadFile(uri, tblocalFile.Text);
client.Dispose();
HTTP Post Code...
WebClient client = new WebClient();
if (tbpassword.Text != "" && tbUsername.Text != "")
{
NetworkCredential auth = new NetworkCredential(tbUsername.Text, tbpassword.Text);
client.Credentials = auth;
}
if (tbProxyAddress.Text != "" && tbProxyPort.Text != "")
{
WebProxy proxy = new WebProxy(tbProxyAddress.Text, Convert.ToInt32(tbProxyPort.Text));
if (tbProxyUsr.Text != "" && tbProxyPwd.Text != "")
proxy.Credentials = new NetworkCredential(tbProxyUsr.Text, tbProxyPwd.Text);
client.Proxy = proxy;
}
Uri uri = new Uri(tbURL.Text);
System.Collections.Specialized.NameValueCollection collect = new System.Collections.Specialized.NameValueCollection();
collect.Add("input", "Ronak");
collect.Add("submit", "Submit");
byte[] btArray = client.UploadValues(uri, "POST", collect);
//byte[] btArray = client.UploadFile(uri, "POST", tblocalFile.Text);
MessageBox.Show(Encoding.UTF8.GetString(btArray));
client.Dispose();
|
|
|
|
|
Hi all,
I'm working on a project using Visual Studio2005. I have saved an image path to the database. The code is something like this:
-----------------------------------------------
.
.
.
OpenFileDialog openImgFile = new OpenFileDialog();
if (openImgFile.ShowDialog() == DialogResult.OK)
{
imgPath= openImgFile.FileName;
pictureBox1.Image = Image.FromFile(imgPath);
}
cmdStr = "insert into img_tbl(imgID,imgPath)values('01',@path)";
cmd = new SqlCommand(cmdStr, cnn);
SqlParameter path = new SqlParameter("@path", SqlDbType.NVarChar, 225);
path.Value = imgPath;
cmd.Parameters.Add(path);
cmd.ExecuteNonQuery();
.
.
.
What I got from that is an image path storing in the database, something like this:
C:\Documents and Settings\Desktop\foto_311.jpg
But the problem is when I use this path to get an image to display on a form, it dosen't work!
If I change a little like this:
C:\\Documents and Settings\\Desktop\\foto_311.jpg
then it works.
So can anyone tell me how to change it before being saved?
Thankz
|
|
|
|
|