Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all 8156 articles
Browse latest View live

How to set nullable property to anonymous

$
0
0

How do i set the properties of "result" to nullable int. The code below doesnt work

<Package><Document><ID>0</ID><UID/><SequenceNumber>0</SequenceNumber></Document><Document><ID/><UID/><SequenceNumber>1</SequenceNumber></Document><Document><ID>2</ID><UID/><SequenceNumber/></Document></Package>

static void Main(string[] args) { var result = XDocument.Parse(GetXml()).Root.Elements() .Select(x => new {

//this doesnt work ID = (int?)(x.Element("ID")), UID = (int?)(x.Element("UID")), SequenceNumber = (int?)(x.Element("SequenceNumber")), }).ToList(); }




Is there any limitation for the information that a window service can exchange with an application?

$
0
0
Is there any limitation for the information that a window service can exchange with a windows application?

Control creation based on control_id stored in Model

$
0
0
In my database, i have a column called control_id which consists value like 1,2,3,4. Based on this value, i have to generate controls like Text box, Dropdownlist and Check box. (For example, if my control_id is 1,then application has to generate Text box, and for 2, dropdownlist and so on) I am completely new to MVC. Can anyone point me in right direction to implement this scenario?

Voice Recording Format at 8000 Hz,16 Bit, Mono

$
0
0
Hi, Im creating a program using c# to record voice recording which base on the system setting. So i require to be able to set the voice recording format to 8000Hz, 16 bit  in the system but not using other apps. So im looking for voice recording format at 8000 Hz,16 Bit, Mono  uncompressed PCM WAVE files. At my knowledge, i only able to find 2 option which is 2 channel, 16 bit 44100 and 48000 Hz recording. Is there any codec for me to download to update it so i can record in 8000 Hz, 16 Bit, mono in uncompressed PCM wave files ?


Thanks!
Daemian

Save & access local machine excel file from SharePoint 2010 server location

$
0
0

 have an upload Excel functionality which will upload the data from excel to a Asp.net Text Box control. Currently my asp.net application is hosted on SharePoint 2010 environment. When the excel is uploaded it will be saved on the server machine location(Example : C:\Test) and it will be called again from the server location to process the data by the access database engine and uploaded to text box control on sever as comma separated values.

The challenge is we cannot save the file on the server location due to security concerns from our admins. Is there a way to save the file in my local machine when i browse and click upload and then pass the same local machine path to server to process my request(Basically we want to save the file on the user local machine instead of server physical path). Can anyone please throw some light on this issue. Below is the code i am using currently to store in the server location(which i want to change it to user local machine).

strTarget =Server.MapPath(fileUpload.FileName);string[] arrCheckExtension = strTarget.Split('.');if(arrCheckExtension.Length>=2){if(arrCheckExtension[1].ToString().Equals("xls")|| arrCheckExtension[1].ToString().Equals("xlsx")){
                            fileUpload.SaveAs(strTarget);
                            strConnForExcel =String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;""", strTarget);
                            strQueryForExcel =String.Format("select id from [{0}$]","Test");OleDbDataAdapter adap =newOleDbDataAdapter(strQueryForExcel, strConnForExcel);
                            ds =newDataSet();
                            adap.Fill(ds);if(ds.Tables[0].Rows.Count>0){for(int i =0; i < ds.Tables[0].Rows.Count; i++){if(strids ==""){
                                        strids += ds.Tables[0].Rows[i]["id"].ToString();}else{
                                        strids +=","+ ds.Tables[0].Rows[i]["id"].ToString();}}
                                txtUpload.Text= strids;}}else{Response.Write("<script language='javascript'>alert('Please Select File with .xls or xlsx Extension');</script>");}}

Regex

$
0
0
Is this correct?

Regex r = new Regex("X");
string[] v = r.Split("oneXtwoXthree"); // v = [one, two, three]

But:

Regex r = new Regex("(X)");
string[] v = r.Split("oneXtwoXthree"); // v = [one, X, two, X, three]

In my opinion the result must be the same.

khetan

$
0
0
we hohe your help to setup the program

System.ComponentModel.Win32Exception (0x80004005): The specified server cannot perform the requested operation

$
0
0

Greetings,

I have a program running a FileSystemWatcher to watch for changes to a log file on a mapped drive (code below).  This same program is running on three different production machines and two of them are working perfectly.

On the third machine every few seconds I receive a monitor error that contains the line;

  'System.ComponentModel.Win32Exception (0x80004005): The specified server cannot perform the requested operation'.

This message is very ambiguous and general (at least to me).  Have googled it but to no avail.  The inner exception is blank so it's of no help.

Can anyone please shed some light on what this error means and perhaps why it would be occurring?

Thank you.

Dale Hoffman

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FileSystemWatcherTest
{
    class Program
    {
        static FileSystemWatcher _monitor;

        static void Main(string[] args)
        {
            StartWatcher();
            Console.WriteLine(@"Press any key to exit.");
            Console.ReadKey();
        }

        private static void StartWatcher()
        {
            try
            {
                _monitor = new FileSystemWatcher();
                //_monitor.InternalBufferSize = 16384;
                _monitor.Path = @"L:\";
                _monitor.IncludeSubdirectories = false;
                _monitor.Filter = "DPJobState*.txt";
                _monitor.NotifyFilter = NotifyFilters.LastWrite;
                _monitor.Error += OnMonitorError;
                _monitor.Changed += new FileSystemEventHandler(OnMonitorChanged);
                _monitor.EnableRaisingEvents = true;
            }
            catch (Exception ex)
            {
                _monitor.Dispose();
                using (StreamWriter swLog = new StreamWriter(@"c:\Tools\Log\AutoCreditingMonitorLog.txt", true))
                    swLog.WriteLine(DateTime.Now.ToString() + ex);
                System.Threading.Thread.Sleep(1000);
                StartWatcher();
            }
        }

        private static void OnMonitorChanged(object sender, FileSystemEventArgs e)
        {
            _monitor.EnableRaisingEvents = false;
            using (StreamWriter swLog = new StreamWriter(@"c:\Tools\Log\AutoCreditingLog.txt", true))
                swLog.WriteLine(DateTime.Now.ToString() + " Log file changed");
            _monitor.EnableRaisingEvents = true;
        }

        private static void OnMonitorError(object source, ErrorEventArgs e)
        {
            _monitor.Dispose();
            using (StreamWriter swLog = new StreamWriter(@"c:\Tools\Log\AutoCreditingErrorLog.txt", true))
                swLog.WriteLine(DateTime.Now.ToString() + " Monitor error detected: " + e.GetException());
            System.Threading.Thread.Sleep(1000);
            StartWatcher();
        }
    }
}


Dale Hoffman


Certificate validation time delay when VPN is turned on

$
0
0
Hi, I've faced with problem with time delay during certificate validation. I'm using WIF and JWT Token Handler extension for my claim-based authentication. And in case VPN is turned on I have time delay(about 20 seconds) during certificate validation. Also I found the same behaviour with time delay when I opened Certificate Storage under Microsoft Management Console. Is there any way to avoid this issue?

WIA in C# .NET .

$
0
0

Hi

Is there any good full example in MSDN website using WIA(Windows Image Aquisition)  in  C#  .NET 

Thanks,

Rajeev

Installing a custom .dll (I appollogize in advance if this is the wrong forum)

$
0
0
I have written several PowerShell cmdlets all contained in one .dll. After making updates to the .dll is it necessary to uninstall/reinstall the .dll using the installutil program or is it acceptable to just copy the new .dll over the originally installed one?

What is the equivalent of My.Settings.DebugMode in C#

$
0
0
What is the equivalent of My.Settings.DebugMode in C#

Choose a job you love, and you will never have to work a day in your life. - Confucious

XmlDocument class to binary format conversion

$
0
0

Hello community,

  I'm designing a desktop app, and reusing code that stores it's data in Xml text format. I use the System.Xml namespace and the XmlDocument, XmlAttributes to achieve that goal.

  What I would like is to convert my XmlDocument object and save it to disk as a binary and load it from binary, so it's no longer human readable. How can I do this?

Thanks in advance.

how to export data from datatable to Excel and save in solution explorer

$
0
0
Please provide solution to this how to export data from datatable to Excel and save in solution explorer

type exists in BOTH assemblies (BUT FOR GOOD REASONS)

$
0
0

Hi Folks

I've been kind of forced between a "rock and a hard place" in terms of what we refer to as our "Global Directory" (SSO - single sign-on services) and how SQL Server 2012 SSRS works as well.

1. What I need to do with SSRS 2012 is a "hardwired" at .Net v3.5 (its a Microsoft.ReportServices.Interfaces.dll kind of thing).

2. What we've hardwired into our own development for SSO is .Net v4.5.1 (and no, unfortunately our software environment is NOT VERSIONED/wasn't history'd and checkpointed for use at various versions (for adaptability in area like this), etc..

3. I've managed to construct a CONSOLE application which does the up-n-down "thunking" between the .Net versions with a main program and 2 dlls. So we basically go back and forth WITHOUT ISSUE (SSRS v3.5-up/down thunk-v4.5.1 SSO). If you REALLY want the previous gory details, you can look here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/d27d3c40-66cd-45a8-b036-b3d1211ace2f/typegettypefromprogid-not-returning-systemmarshalbyrefobject?forum=netfxbcl&prof=required (there's diagrams, discussions, etc.)

The way this up-and-down thunking was done, was via  Interfaces (and was the only way I know of to do anything like this). The "trickery" was binding Interfaces from different DLLs with the same name.

This works great in a simple CONSOLE application, but in the context of SSRS and COM registered assemblies it can come around and bite you quickly ;)

Back to my problem... When I execute this code:

            try
            {
                Type myClassAdapterType = Type.GetTypeFromProgID("Net35ToNet4xAdapter.MyClassAdapter");
                Object myClassAdapterInstance = Activator.CreateInstance(myClassAdapterType);
                Net35ToNet4xAdapter.IMyClassAdapter myClassAdapter = (Net35ToNet4xAdapter.IMyClassAdapter)myClassAdapterInstance;

on the last line, I get the error:

The type 'Net35ToNet4xAdapter.IMyClassAdapter' exists in both 'DMx.CustomDataProcessingExtension.dll' and 'Net35ToNet4xAdapter.dll'...

Which is correct, IMyClassAdapter DOES exist in both.  This is the only way to go back and forth in .NET.

Is there a simple way to cast/cast as the myClassAdapterInstance as a particular dll with that mentioned interface?

Thanks

Rob





Rob K


CancellationTokenSource is not working

$
0
0

I have a producer-consumer application, I wrote it as a WPF. For the convince, I set the project's property as console, so I can simply using Console output.

Basically I add integers to a BufferBlock queue in producer, when I click the Start button, it runs producer and consumer. Now I want to cancel it by clicking cancel button then displaying "Stop" . So I passed CancellationToken to the method but it is not working, which means it keeps send the output.

The main code:

public static BufferBlock<int> queue = new BufferBlock<int>(new DataflowBlockOptions { BoundedCapacity = 1000 });
private CancellationTokenSource cTokenSource;
private static CancellationToken cToken;

 private void Start_Click(object sender, RoutedEventArgs e)
        {
            cTokenSource = new CancellationTokenSource();
            cToken = cTokenSource.Token;
            var producer = Producer();
            var consumer = Consumer();

        }

async Task Consumer()
        {
            var executionDataflowBlockOptions = new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 1,
                CancellationToken = cToken
            };
            var consumerBlock = new ActionBlock<int>(
i =>
{
    if (cToken.IsCancellationRequested)
        return;
    RunScript(i, cToken); Dispatcher.BeginInvoke((Action)delegate()
    {
        items.Add(new TodoItem() { Number = i });
    });
},
executionDataflowBlockOptions);

            queue.LinkTo(
consumerBlock, new DataflowLinkOptions { PropagateCompletion = true });
            await consumerBlock.Completion;
        }

        private void RunScript(int i, CancellationToken cToken)
        {
            Console.WriteLine("Processing " + i);
            for (int j = 0; j < 100; j++)
            {
                Console.WriteLine(j);
                 Thread.Sleep(1000);
            }
            Console.WriteLine("------------");
            cToken.Register(() =>
                   {
                       Console.WriteLine("Stop");
                       return;
                   });
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            cTokenSource.Cancel();
        }

I also provided a full clean solution on the OneDrive.

The file name is "CancellationTokenIsNotWorking.zip". Thanks for help.


Correct way to launch a file editor from WinForms app

$
0
0

I am trying to offer users the ability to edit image files from a WinForms application.  The files are sourced on a network drive.  I want to launch MSPaint to allow editing and then the Save needs to save it back to the network drive location. Using System.Diagnostic.Process to launch results in a sharing violation condition because the System.Diagnostics.Process has a lock on the file.  I have to close the WinForms application to remove the lock which is a useless solution.  If the file is sourced from My Documents, the System.Diagnostics.Process will not create a lock.  So, is there a way to launch MSPaint to edit the file from a network location or is there a setting to create the process without locking the file?  Perhaps the ProcessStartInfo has a setting I am not aware of that launches a process as a standalone, decoupled process?

Scanned folder in WIA(Windows Image Acquisition) in C# .NET

$
0
0

Hi,

How to find the saved scanned file folder in WIA(Windows Image Acquisition)  C#  .NET .

Thanks,

Rajeev

how to synchronize my timer together with my trackbar c#?

$
0
0

Hello to everyone :D

well some days ago i have been reading some information about c#, well after that i decided to make a Mp3 player,

i have read a lot of information for the "timer" but i haven't made it...

well nowadays i want to make the trackbar works together with the timer. it's means when i  move the trackbar and the timer show me the time's music  in a label right. i have the code for the trackbar! i have synchronized my trackbar with the music it means when i move the trackbar the music works very well,


but i haven't found the other code for the "TRACKBAR  works together with TIMER"

To be honest i had made a "stopwatch" but it didn't work very well, when i compiled the code!. 


thanks for all the answer.

thanks you for take the time to answer me :)

Best Wishes 

How can I view all exceptions in our app?

$
0
0

Hi;

We're trying to track all exceptions when someone uses our program. Is there a way, that won't noticeably impact performance, where we can copy all handled and unhandled exceptions?

We don't care about ones that are handled within the .NET runtime because those theoretically are not a bug/problem.

??? - thanks - dave


What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

Viewing all 8156 articles
Browse latest View live