|
With what? I did what Bill should have done if he was truly concerned with the OP learning something. Instead, he chose to treat everyone that provided real answers like they were 12-year-olds, and scold us for just giving the OP what he wanted.
".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 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
John Simmons / outlaw programmer wrote: ... all methods technically return a value, whether it's void or some other type A method with the 'void specification does not return anything: if the compiler encounters a 'return statement in a 'void Method followed by any .NET Type instance, it will throw an error. Of course, the 'return flow of control statement ... by itself ... is valid.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
modified 15-Apr-18 4:07am.
|
|
|
|
|
Hello
Below id my C# code for finding the status of a website. I get a ok, what I want is to get a 200.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace _200_Test2
{
class Program
{
static void Main(string[] args)
{
{
WebRequest request = WebRequest.Create("http://www.cnn.com/");
try
{
using (WebResponse response = request.GetResponse())
{
HttpWebResponse httpResponse = (HttpWebResponse)response;
Console.WriteLine(httpResponse.StatusCode);
Console.ReadKey();
}
}
catch (WebException e)
{
using (WebResponse response = e.Response)
{
HttpWebResponse httpResponse = (HttpWebResponse)response;
Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
using (Stream data = response.GetResponseStream())
{
string text = new StreamReader(data).ReadToEnd();
Console.WriteLine(text);
}
}
}
}
}
}
}
I try for days now to get a simple 200.
Maybe someone can look at this and tell me what I am going wrong.
Thank You
renny
|
|
|
|
|
But 200 is OK! The property you are referring to also says the same, HttpStatusCode Enumeration (System.Net), only the difference is that your property is an enum and it might be getting translated to a readable form. Try this,
Console.WriteLine((int)httpResponse.StatusCode);
But again, remember, it is always better to use the readable/understandable names of the state; OK, Bad request, etc. Rather than the HTTP codes.
And yes, similarly for the error printing, you would need to use the following,
Console.WriteLine("Error code: {0}", (int)httpResponse.StatusCode);
Read the guide on MDN for more on HTTP codes and also the MSDN link I provided above to understand a bit more about this HTTP status code and how .NET supports it.
200 OK - HTTP | MDN
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thank you all very much
|
|
|
|
|
See HttpStatusCode Enumeration (System.Net)[^] for the enumeration details. The 200 value is interpreted by the HttpWebResponse object. If you want to see the actual status line then you need to use POST/GET to receive the raw HTML source.
|
|
|
|
|
Thank you all for your help.
renny
|
|
|
|
|
Hello,
I created a new user defined function in excel using c#,what i want to get is when a user open an excel file, clic on a cell and write =myFunction() press enter, data should be displayed in the excel file. these data are retrieved from sql server database and stocked in a 2D array of object, my problem is when i try to display this array in excel range i got this exception
Exception de HRESULT : 0x800A03EC
Below is my code :
public static void LoadViewData()
{
var target = (ExcelReference)XlCall.Excel(XlCall.xlfCaller);
var sheetName = (string)XlCall.Excel(XlCall.xlSheetNm, target);
var application = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;
var sheet = application.Sheets[Regex.Replace(sheetName, @"\[[^]]*\]", string.Empty)];
object[,] result = LoadFromDbData();
var startCell =sheet.Cells[target.RowFirst + 1, target.ColumnFirst];
var endCell =sheet.Cells[target.RowFirst+ result.GetUpperBound(0) - result.GetLowerBound(0) + 1,
target.ColumnFirst+ result.GetUpperBound(1) - result.GetLowerBound(1) + 1];
var writeRange = sheet.Range[startCell, endCell];
writeRange.Value2 = result;
}
target returns the correct value of the cell where the user has written the formula (=myFunction())
sheetName returns the correct activeSheet in which the user writes the formula
result contains the data retrieved from sql server, it is an array of object[854,8]
startcell and endcell represents the range from which cell to which cell data will be displayed
when debugging, all variables contain the correct values, the exception appears in this instruction :
writeRange.Value2 = result;
Anyone has already worked with this or can help please ?
Thanks
|
|
|
|
|
0x800A03EC in Excel is a rather generic error.
In this case, you can't assign an array to a single cells Value2 property. You actually have to iterate through each cell in the array and assign the value of that cell to the corresponding cell in the worksheet.
|
|
|
|
|
We have a medical device that is connected to the LAN but is not on Active Directory. The instrument is running Windows Embedded as a service.
When a user logs into the device we want to validate them against AD. I've found plenty of example of validating users, but they all seem to assume that the code is being run under an account of an AD user.
How to I validate a user against AD when the instrument isn't on AD?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The device should able to connect AD to validate the user.
Or
you could create a web service that can connect to AD and let the medical device call that web service to verify the user.
|
|
|
|
|
Keviniano Gayo wrote: The device should able to connect AD to validate the user.
Unless someone logs into Windows on the device, it won't connect. Here's how I'm trying
using (var context = new PrincipalContext(ContextType.Domain, credentials.ServerName, credentials.UserName, credentials.Password))
{
validated = context.ValidateCredentials(userName, password);
}
Again, this works if someone is logged into Windows. if not, it doesn't
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I see.. i haven't tried connecting to AD without logging into windows.
I used the same code as above to verify the user in AD.
Perhaps calling a custom web service to verify a user in AD would be the best route.
|
|
|
|
|
Hi,
I have a folder named "Data_base" stored somewhere in my pc. I need the full path of this folder by searching only its name in C#.
void getPath(string name)
{
// need code
}
string folderName="Data_base";
getPath(folderName);
Please Help . . .
|
|
|
|
|
See Directory Methods (System.IO)[^]. You will need to start at the root and enumerate all directories recursively until you find the one you are looking for.
|
|
|
|
|
thanks for your reply.
Got the solution, but ends up with another problem "Access to the path 'D:\System Volume Information' is denied" . And i didn't find any solution to this. So instead of placing the Data_base anywhere i decided to place it in the application installation folder itself.
Now the path can be easily read by using the code in runtime
string appFileName = Environment.GetCommandLineArgs()[0];
string directory = Path.GetDirectoryName(appFileName);
MessageBox.Show(directory);
|
|
|
|
|
Quote: The System Volume Information folder is a hidden system folder that the System Restore tool uses to store its information and restore points. There is a System Volume Information folder on every partition on your computer.
Never store user data in the application folder. A normal user did not have write access when using the recommended Progam Files folder. Use one of the application data folders instead. Which one to use depends on roaming support and if shared access is required. See the AppData properties in the Application Class (System.Windows.Forms)[^] to get these pathes.
|
|
|
|
|
Thanks for the reply...
i don't want to use System Volume Information folder. But during enumeration process automatically the checking comes here, then generates an exception and terminates further execution. Is there any method to avoid these kind of system folders checking during enumeration?.
|
|
|
|
|
When you expect exceptions to be thrown catch them to avoid that the application terminates. In this case just ignore access denied exceptions and continue.
But there is no need to enumerate all directories when using a standard Windows folder for your application data.
|
|
|
|
|
|
thanks for the reply. . .
|
|
|
|
|
private static List<string> BadNames = new List<string>{"Adobe","CPMigrator","ServicePack","Symantec", "Server", "TumbleWeed"};
private static string targetFolder = "Common7";
static void Main(string[] args)
{
List<string> folders = GetFolders(@"C:\Program Files\");
string found = folders.FirstOrDefault(x=>x.ToUpper().EndsWith(targetFolder.ToUpper()));
}
public static List<string> GetFolders(string path)
{
List<string> folders = new List<string>();
foreach(string bad in BadNames)
{
if (path.ToUpper().Contains(bad.ToUpper()))
{
return folders;
}
}
try
{
folders = Directory.GetDirectories(path, "*.*", SearchOption.TopDirectoryOnly).ToList();
for (int i = 0; i <folders.Count; i++)
{
folders.AddRange(GetFolders(folders[i]));
}
}
catch (Exception)
{
}
return folders;
}
".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 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 13-Apr-18 9:41am.
|
|
|
|
|
Smallest window in a string containing all the characters of another string
|
|
|
|
|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Looks a bit spammy to me.
|
|
|
|