|
actually i want to open the file which is stored in the database in blob format.
i was able to save that perticular file into any of folders in the system
sample code is here.
string ATTACHEMENTID1 = "";
private void DgToolsList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
ATTACHEMENTID1 = DgToolsList.Rows[e.RowIndex].Cells[0].Value.ToString();
string FileName = DgToolsList.Rows[e.RowIndex].Cells[1].Value.ToString();
if (e.ColumnIndex == 1)
{
saveFileDialog1.Title = "Open File";
saveFileDialog1.Filter = "All Files|*.*|JPEG Images|*.jpg|GIF Images|*.gif|BITMAPS|*.bmp";
saveFileDialog1.FileName = FileName.ToString();
saveFileDialog1.ShowDialog();
//txtAttachment.Text = openFileDialog1.FileName;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
byte[] buffer = GetFileFromDB(ATTACHEMENTID1);
int ArraySize = new int();
ArraySize = buffer.GetUpperBound(0);
FileStream fs1 = new FileStream(saveFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Write);
fs1.Write(buffer, 0, ArraySize);
fs1.Close();
MessageBox.Show("File Save to " + saveFileDialog1.FileName);
}
}
}
GetFileFromDB(string atachmenet) is the method to read the blog data from the database
but i want to open the file directly istead of saving it and open it again.
please provide me with some solution for it .
|
|
|
|
|
And what have you tried? Post some code with specific problems if you want help.
shaik abdul gani wrote: expecting an responce from your side
And do not demand things, its rude.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
sorry for that.
actually i want to open the file which is stored in the database in blob format.
i was able to save that perticular file into any of folders in the system
sample code is here.
string ATTACHEMENTID1 = "";
private void DgToolsList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
ATTACHEMENTID1 = DgToolsList.Rows[e.RowIndex].Cells[0].Value.ToString();
string FileName = DgToolsList.Rows[e.RowIndex].Cells[1].Value.ToString();
if (e.ColumnIndex == 1)
{
saveFileDialog1.Title = "Open File";
saveFileDialog1.Filter = "All Files|*.*|JPEG Images|*.jpg|GIF Images|*.gif|BITMAPS|*.bmp";
saveFileDialog1.FileName = FileName.ToString();
saveFileDialog1.ShowDialog();
//txtAttachment.Text = openFileDialog1.FileName;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
byte[] buffer = GetFileFromDB(ATTACHEMENTID1);
int ArraySize = new int();
ArraySize = buffer.GetUpperBound(0);
FileStream fs1 = new FileStream(saveFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Write);
fs1.Write(buffer, 0, ArraySize);
fs1.Close();
MessageBox.Show("File Save to " + saveFileDialog1.FileName);
}
}
}
GetFileFromDB(string atachmenet) is the method to read the blog data from the database
but i want to open the file directly istead of saving it and open it again.
please provide me with some solution for it .
|
|
|
|
|
Sorry, you are not making sense. Looking at your code, you read the data from the database and save it to a file. Simple enough. What doesn't make sense is
shaik abdul gani wrote: but i want to open the file directly istead of saving it and open it again.
So use the byte[] buffer that you populated from the database. Whats the problem?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Response: Looks like pretty straightforward and justified requirements.
|
|
|
|
|
I have a function which converts a bytearray to string. Following is the function :
//The bytearray value is getting from database. From the db, it is returning as varbinary.
-----------------------------------------------------
byte[] actual;
actual = target.GetFileBytes(projectFileId);
------------------------------------------------------
string strtest = "";
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
strtest = enc.GetString(actual);
This is working fine. But the issue is, when I check the variable strtest, I can see the value as two boxes with a question mark and commas. How should I get the correct string? Any help please?
Thanks
Meeram395.
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
Hi,
i would guess that ASCIIEncoding may not seem the correct encoding for your byte-array. How did you stored the file-bytes into your database? How did you converted the input string into the byte-array? And what kind of file is this? A plain text-file?
A workaround would be to store the byte-array as file and then to read the file to get the content as string.
Regards
Sebastian
|
|
|
|
|
You have to use the same encoding as was used to create the byte array before it was put in the database.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hello
QUESTION 1:
If I want to handle properties of types under "System.Collections" is there a better way for me to rewrite the following?
Type oTypeInfo = lstCustomers.GetType();
if(oTypeInfo.PropertyType.NameSpace=="System.Collections") {
// do something accordingly
}
I don't like string comparison/substring and prefer not to hardcode "System.Collections". Anyway to do this? Prefer something out-of-the-box from .NET itself for instance
if(oTypeInfo.isCollection) { // This attrib does not exist unfortunately.
// do something
}
QUESTION 2:
How can instantiate generic type in runtime?
Type oTypeInfo = lstCustomers.GetType();
if(oTypeInfo.PropertyType.NameSpace=="System.Collections") {
// do something accordingly
CustomAttr<otypeinfo.propertytype> newAttrib = new CustAttr<otypeinfo.propertytype>;
newAttrib.Value = oInfo.GetValue();
this.myList.Add(newAttrib);
}
As you see, CustAttr is generic
class CustAttr<T> {
... bunch of stuff ...
}
Thanks
<div class="ForumMod">modified on Friday, December 5, 2008 4:52 AM</div>
|
|
|
|
|
devvvy wrote: I don't like string comparison/substring and prefer not to hardcode "System.Collections". Anyway to do this? Prefer something out-of-the-box from .NET itself for instance
if(oTypeInfo.isCollection) { // This attrib does not exist unfortunately.
// do something
You've got the right idea here. Check to see if the object is implementing ICollection.
if( lstCutomers is ICollection)
BTW: Hungarian notation is really on the way out.
|
|
|
|
|
1. is ICollection - works thanks!
2. Hungarian notation - code different languages and framework I no longer remember which is which!
3. any chance there's a way to instantiate generic <t> at runtime? (QUESTION 2)
Many thanks!~
dev
|
|
|
|
|
devvvy wrote: 3. any chance there's a way to instantiate generic at runtime? (QUESTION 2)
Last I checked, no there isn't. Generic types are determined and code written by the compiler at compile time. This is because Generics are "syntactic sugar", basically, writing overloaded code for you to handle each type (T) that the compiler finds instances of.
|
|
|
|
|
|
Dear all,
perhaps someone can help me. I'm trying to write a program that retireves information from my amazon seller account, but it fails to get the cookies Amazon sends me.
I have the following code:
CookieContainer cookies = new CookieContainer();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.amazon.de/gp/sign-in.html?ie=UTF8&email=...@web.de");
req.CookieContainer = cookies;
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
The cookies do not end up in the cookie container of the response, even though I can see them in the response header. Cookies from another website work.
I have now discovered that the program perhaps cannot handle the format of the set-cookie header correctly when parsing the cookies.
The cookies that don't work have the expiration date given as
Expires=Fri Dec 05 12:05:33 2008 GMT
while cookies from another host that can be parsed have it as
Expires=Fri, 05-Dec-08 12:05:33 GMT
Could this really be the cause for the cookie to be rejected by automatic parsing? If so, how can I set the format string for the application so it will parse the cookies correctly?
Any help is greatly appreciated
Reiner
|
|
|
|
|
I have the same problem (in amazon as well
I use the following regexp:
string regexp = "(?<name>[^=]+)=(?<val>[^;]+)[^,]+,?";);
MatchCollection myMatchCollection = Regex.Matches(cookiesStr, regexp);
foreach (Match myMatch in myMatchCollection)
{
string cookieName = myMatch.Groups["name"].ToString();
string cookieVal = myMatch.Groups["val"].ToString();
Cookie cookie = new Cookie(cookieName, cookieVal);
cookies.Add(cookie);
}
Note that I only care about the cookie name/value...
good luck
Elia
|
|
|
|
|
I am trying to create an application where, if new drive has been detected by the windows operating system, an event on the application is triggered.
Although what i was planning to do is the application to check for new drives in a given time interval but seems like that is not the appropriate thing to do.
Any suggestions?
|
|
|
|
|
hello
use the concept of threads
thks
|
|
|
|
|
I'm actually using thread to keep on scanning on every time interval but don't you think that's not a good idea?
|
|
|
|
|
Hi,
for a Control (a Form is a Control) you can override WndProc and check for
wParam==WM_DEVICECHANGE
That will give you an event whenever a device (such as a camera, USB memory stick, ...)
gets added or removed.
|
|
|
|
|
Try responding to the WM_DEVICECHANGE[^] window message. A WParam value of DBT_DEVICEARRIVAL[^] should indicate a new cd/usb drive.
Will probably only work if you have auto insert notification turned on for the drive.
[Edit: Oops, should have hit refresh before posting. I agree with Luc]
Simon
|
|
|
|
|
Hello,
I get the error "No conenction could be made because the target machine actively refused it 192.168.1.2:1234"
It works very fine in localhost but when i tried to connect to other pc on web it gives me above error.
So will you please help me?
Thank you.
|
|
|
|
|
Are you running the server on that PC? Did you make sure the firewall is not blocking?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Hello,
I dont know how to make the firewall settings for that port.
|
|
|
|
|
krinaljariwala wrote: I dont know how to make the firewall settings for that port.
That is outside the scope of a C# question. Ask your network admin.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
I want to load data that have already saved in a file to a listbox. My code here doesn't work, there's nothing happen in the listbox eventhough there are some items in the file that should be loaded to the listbox. Where is my mistake?
//the code below to load, but nothing happen
private const string Filename = "DDBlock.txt";
public void Main(String[] args)
{
this.listBoxBlockedNumberDD.Items.Clear();
if (File.Exists(Filename) == true)
{
using (StreamReader sr = File.OpenText(Convert.ToString(Filename)))
{
foreach (string Item in Filename)
{
listBoxBlockedNumberDD.Items.Add(sr.ReadLine());
}
}
}
}
//the code below to save item in listbox to a file, it works and the item is saved to the file.
private void menuItemDD_Click(object sender, EventArgs e)
{
listBoxBlockedNumberDD.Items.Add(RemoveText(textBoxPhoneNumber1.Text.Trim()));
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Filename, true))
{
foreach (string Item in this.listBoxBlockedNumberDD.Items)
{
sw.WriteLine(Item);
}
sw.Close();
}
textBoxPhoneNumber1.Text = string.Empty;
}
|
|
|
|