Monday, April 23, 2012

from clipboard copy files specified path

? send files my to cliboard and ? want copy all wthin listbox files specified path a with click to button for example desktop,to folder such as my have single problem ? don t get selecteditems from listbox and ? don t copy now how ? can copy



CODE HERE



public partial class Form1 : Form
{
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetClipboardViewer(IntPtr hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
IntPtr SonrakiClipboardOgesi;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
SonrakiClipboardOgesi = SetClipboardViewer(this.Handle);
}
protected override void WndProc(ref Message m)
{
int WM_DRAWCLIPBOARD = 0x0308;
int WM_CHANGECBCHAIN = 0x030D;

if (m.Msg == WM_DRAWCLIPBOARD)
{
ClipboardOku();
SendMessage(SonrakiClipboardOgesi, m.Msg, m.WParam, m.LParam);
}
else if (m.Msg == WM_CHANGECBCHAIN)
{
if (m.WParam == SonrakiClipboardOgesi)
{
SonrakiClipboardOgesi = m.LParam;
}
else
{
SendMessage(SonrakiClipboardOgesi, m.Msg, m.WParam, m.LParam);
}
}

base.WndProc(ref m);
}

private void ClipboardRead()
{
StringCollection col = new StringCollection();
col = Clipboard.GetFileDropList();
for (int i = 0; i < col.Count; i++)
listBox1.Items.Add(col[i]);
listBox1.SelectionMode = SelectionMode.MultiSimple;
for (int i = 0; i < listBox1.Items.Count; i++)
listBox1.SetSelected(i, true);
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ChangeClipboardChain(this.Handle, SonrakiClipboardOgesi);
}

private void button1_Click(object sender, EventArgs e)
{
// ? make a with click copy within listbox files specified path
//What code I should write here
}
}
}




See if file is empty

How to a check if a file is empty in Java 7?

I tried it using the available() method from ObjectInputStream, but it returns always zero even if the the file contains data.





RavenDB disk storage

I have a requirement to keep the RavenDB database running when the disk for main database and index storage is full. I know I can configure provide a drive for storage with config option - Raven/IndexStoragePath



But I need to design for the corner case of when the this disk is full. What is the usual pattern used in this situation. One way is to halt all access while shutting the service down and updating the config file programatically and then start the service - but it is a bit risky.



I am aware of sharding and this question is not related to that , assume that sharding is enables and I have multiple shards and I want to increase storage for each shard by adding a new drive to each. Is there an elegant solution to this?





ASPX & SQL returning multiple recordsets - identify them

I am creating a simple report in aspx.



I have a stored procedure that I'm calling to get 5 recorsets.



First 4 have 7 columns and second has 6 columns.



This is my C# code:



protected void bindGridView()
{
string _connStr = ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString();
DataSet dSet = new DataSet();
try
{
using (SqlConnection conn = new SqlConnection(_connStr))
{
using (SqlCommand cmd = new SqlCommand("MyProcedure", conn))
{
cmd.CommandTimeout = 120;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@d", SqlDbType.VarChar).Value = dlDzial.SelectedValue;
cmd.Parameters.Add("@g", SqlDbType.Int).Value = dlGrupa.SelectedValue;
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
ad.Fill(dSet);
if (dSet.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = dSet.Tables[0];
GridView1.DataBind();
}
else
{
ShowNoResultFound(dSet.Tables[0], GridView1);
}
if (dSet.Tables[1].Rows.Count > 0)
{
GridView2.DataSource = dSet.Tables[1];
GridView2.DataBind();
}
else
{
ShowNoResultFound(dSet.Tables[1], GridView2);
}
if (dSet.Tables[2].Rows.Count > 0)
{
GridView3.DataSource = dSet.Tables[2];
GridView3.DataBind();
}
else
{
ShowNoResultFound(dSet.Tables[2], GridView3);
}
if (dSet.Tables[3].Rows.Count > 0)
{
GridView4.DataSource = dSet.Tables[3];
GridView4.DataBind();
}
else
{
ShowNoResultFound(dSet.Tables[3], GridView4);
}
lbl1.Visible = lbl2.Visible = lbl3.Visible = lbl4.Visible = true;
}
}
}
}
catch (Exception ex)
{
lblErrorMsg.Text = ex.Message;
}
}


But I have a problem. Depending on parameters sometimes recordset 2 & 3 are empty, thats why I get errors when trying to get some values from rows. recordset 4 is then Table[2] and is displayed in gridview 2 (it should be displayed in fourth gridview)



I would like to know how to identify recordsets that come from sql into C#.



I was searching a bit over the internet and I found that I can add extra column to every recordset and using this identify recordsets.



How to identify every recordset, so even if I change order of selects in sql I will be able to map then to correct GridView.





Add Value to RoutValues and keep Current Values in ASP.NET MVC 3

I have a view with two form one of them for declare rows per page. In post action I need my Url be the same and just add new parameter. at now I use like this:



[HttpPost]
public ActionResult Index(FormCollection collection) {

//Calculate Row Count

return RedirectToAction("Index", new { RC = RowCount });

}


with this implementation my all parameters lost and just RC = rowcountnumber replaced.
How can I keep parameters and just add new RC to it? what is fastest way to do it? is any performance issue here?





Global asax and application_endrequest asp.net

Hello i got some question why when i run my method in global.asax it don't run and when i use IHttp module it is workin any advice.
Maybe its caused of context.PostRequestHandlerExecute += new EventHandler(Application_EndRequest);



Is it posible to call it without Module?



Code Example:



Method that i run



        public static void EndSession()
{
HttpContext context = HttpContext.Current;
if (context.Session != null)
{
ISession session = context.Session["Session"] as ISession;
if (context.Session["Session"] != null)
{
if (!session.Transaction.IsActive)
OpenTransaction(session);
session.Flush();
CommitTransaction(session);
session.Close();
context.Session["Session"] = null;
}
}
}


Global



        private void Application_EndRequest(object sender, EventArgs e)
{
NhSessionHelper.EndSession();
}


IHTTPMODULE



  namespace MME.DAL.SesionManager
{
internal class SessionRequest : IHttpModule
{
#region Public Methods

public void Dispose()
{
}

public void Init(HttpApplication context)
{
context.PostRequestHandlerExecute += new EventHandler(Application_EndRequest);
}

Reading a file into a list?

I am trying to read a file into a list, and take every other line from this list, and try to add this to the hashset, and if the result of this operation is false, output the duplicate string. For some reason, it is not working, and i'm not sure what i've done wrong. Thanks .. here is my code:



public class Duplicates
{
public static void main(String[] args)
{

PrintWriter output = null;
BufferedReader input = null;

try
{

input = new BufferedReader(new FileReader(args[0]));
output = new PrintWriter(new FileWriter(args[1]));

List<String> list = new ArrayList<String>();
Set<String> usr = new HashSet<String>();

//Read the lines into lineList
String current;
boolean result;
while ((current = input.readLine()) != null)
list.add(current);


for (int index = 0; index < lineList.size() - 1; index =+2)
{
result = usr.add(list.get(index));
if (result = true)
System.out.println(list.get(index));
}
}//try
catch (Exception exception)
{
System.err.println(exception);
}//catch
finally
{
try {if (input != null) input.close(); }
catch (IOException exception)
{ System.err.println( exception) }
}
}
}