|
What about an "IValidable " interface defining a method "Validate() "?
When "map" and its properties implement it, you could simply call map.Validate() which would encapsulate that logic there.
|
|
|
|
|
Thanks for the reply,the problem is that I would have allot of validation objects everywhere, which wouldn't be very fun to use...
|
|
|
|
|
HOw about
public bool CheckForNulls(object[] thingsThatShouldntBeNull)
{
return thingsThatShouldntBeNull.TrueForAll(x => x != null);
}
CheckForNulls(new object[]{dumbshitCoderField1,dumbShitCoderField2);
|
|
|
|
|
Anyone know why isn't this working?
The line oSheet.Cells[row, column] = data; works correctly and it writes to incrementing columns and rows correctly, but I would like it to see if data contains a \\ and then make it a hyperlink if it does.
Thanks for reading.
oSheet.Cells[row, column] = data;
if ((data.Contains(@"\\")) && (createSheet == false))
{
oSheet.Hyperlinks.Add(oSheet.get_Range(row, column), data, System.Type.Missing, System.Type.Missing, data);
}
|
|
|
|
|
The main problem is the way you are adding the hyperlink.
Instead of Hyperlinks.add you could try Range.ApplyFormula .
Obviously you have to define the formula...
string filexl = @" C:\NewFile.xls";
Workbook wbnew = new Workbook();
Worksheet wsnew = wbnew.Worksheets.Add("New");
wsnew.Rows[0].Cells[0].ApplyFormula(@"=HYPERLINK(""http://www.codeproject.com"",""Urgentzzzz"")");
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
Thanks, I will try this tomorrow
|
|
|
|
|
Hi Dalek,
As an update, I tried this, it does not work in my IDE. I have 2008 express .net 3.5.
I do not have an option for .ApplyFormula and my oSheet.Cells or oSheet.Rows have to be defined with [row, column].As an update,
|
|
|
|
|
URLs tend to contain forward slashes, not backslashes.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Do you know I looked at that and still didn't see it!
That gets an upvote for Olympic Standard Noticing
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
Maybe you need polarizing spectacles?
Always see what is there and don't see what isn't.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Luc!
You are right, this is actually a UNC path
I believe it is still considered a hyperlink, but I may have used the wrong terminology, I used hyperlinks because of the c# method terminology.
|
|
|
|
|
Here is what works, thanks to all that contributed and answered
oSheet.Cells[row, column] = data;
string cell = oSheet.Cells[row, column].ToString();
if ((data.Contains(@"\\")) && (createSheet == false))
{
Excel.Range rng = (Excel.Range)oSheet.Cells[row, column];
oSheet.Hyperlinks.Add(rng, string.Empty, data, "", data);
}
|
|
|
|
|
Hi,
I'm new in DB programming in .net context and I have a question.
If I use a DB in my internet site (es www.mysite.org), I can quering this DB from my desktop application using ADO.net?
Thank a lot.
Alex
|
|
|
|
|
Yes, as long as the database server can be connected to remotely. If it can't be done that way, you can always create a web service to handle the access, and just connect to the web service instead.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
My 5! Good answer since it's most likely that the webserver is behind a firewall. A webservice is a good and viable solution.
|
|
|
|
|
If it's hosted then the database will be likely hiding behind a firewall. Yup, webservices are the way to go
I are Troll
|
|
|
|
|
I second (third?) a Web Service. But I question the need to query from the client side. You'll have to be very wary of SQL injection, but you can probably minimize the risks.
|
|
|
|
|
I want to add directory security to certain folders on my system,
the code is
NTAccount identity = new NTAccount(Account);
SecurityIdentifier sid = (SecurityIdentifier)identity.Translate(typeof(SecurityIdentifier));
DirectoryInfo dInfo = new DirectoryInfo(Dir);
DirectorySecurity dSecurity = dInfo.GetAccessControl(AccessControlSections.Access);
dSecurity.AddAccessRule(new FileSystemAccessRule(sid , Rights, ControlType));
dInfo.SetAccessControl(dSecurity);
but i keep getting this error:
some or all identity references could not be translated
|
|
|
|
|
Why doesnt it download every files in this code?
All files that have been downloaded is shown in the listview, but when i open the folder where the files are, then some of files has not been downloaded.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDownload_Click(object sender, EventArgs e)
{
string p1 = @"\";
string p2 = TBSaveTo.Text;
string p3 = TBSaveAs.Text;
listView1.Items.Clear();
label1.Visible = false;
HttpWebRequest request = null;
HttpWebResponse response = null;
WebClient wc = new WebClient();
string ret = "";
for (int i = 2000; i < 2312; i++)
{
string sFiles = string.Format("http://www.svenskaspel.se/includes/xmlelements/XMLresultat.asp?produktid=30&omgang={0}", +i);
listView1.Items.Add(new ListViewItem(p2 + p1 + "omgang=" + i + p3));
{
try
{
request = (HttpWebRequest)WebRequest.Create(sFiles.Trim());
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = 15000;
response = (HttpWebResponse)request.GetResponse();
ret = new StreamReader(response.GetResponseStream(),
Encoding.Default).ReadToEnd();
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
wc.DownloadFileAsync(new Uri(sFiles.Trim()), String.Format(p2 + p1 + "omgang=" + i + p3, Path.GetExtension(sFiles)));
wc.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(wc_DownloadFileCompleted);
response.Close();
}
catch { }
finally
{
if (response != null)
{
response.Close();
}
}
}
}
}
private void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
this.label1.Visible = false;
}
private void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
this.label1.Visible = true;
}
private void btnBrowse_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
TBSaveTo.Text = folderBrowserDialog1.SelectedPath;
}
}
}
}
/Kenneth
|
|
|
|
|
Member 2168103 wrote: catch { }
that is just stupid.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Agreed - perhaps correct exception handling should be the first lesson for anyone learning to code rather than just an after thought.
|
|
|
|
|
Yes. I also agree very much.
So mixing webclient in that code sucks because it doesnt support concurrent I/O operations like the exception says( ).Thank you!
|
|
|
|
|
You missed the point entirely.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
what do you mean?
first i got books but my understandings in english isnt the best and thats also why it can be difficult for me to understans, so pls explain what i missed???
|
|
|
|
|
Of course it displays the document in the listview. You add it in before you even attempt the download. Looking at your code, it appears from a cursory glance that you are closing your response stream before it has a chance to download the files.
Also, as Luc has said, it's an extremely bad idea to consume exceptions - never, ever, put in code that says catch { } without a good reason (there are some cases where you can get away with this, but they are the exception rather than the norm).
|
|
|
|