Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
T

Thomas ST

@Thomas ST
About
Posts
15
Topics
6
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How to check if Excel-workbook is empty?
    T Thomas ST

    Figured it out :thumbsup:

        private bool IsWorkbookEmpty(Workbook excelBook)
        {
            try
            {
                if (excelBook.Sheets.Count <= 0)
                {
                    return true;
                }
                else
                {
                    foreach (Worksheet sheet in excelBook.Sheets)
                    {
                        Range excelRange = sheet.UsedRange;
                        int test1 = excelRange.Columns.Count;
                        int test2 = excelRange.Rows.Count;
                        int test3 = excelRange.Count;
    
                        if (test1 > 1 || test2 > 1 || test3 > 1)
                        {
                            return false;
                        }
                        else //look for content..
                        {
                            foreach(Range cell in excelRange)
                            {
                                if (cell.Value2 != null)
                                {
                                    string cellValue = cell.Value2.ToString();
                                    if (cellValue.Trim().Length > 0)
                                        return false;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
            retur
    
    C# question com testing tools tutorial

  • How to check if Excel-workbook is empty?
    T Thomas ST

    I'm trying to write a method to find out if a workbook is empty or not.. I'm using Excel 2007 and Microsoft.Office.Interop.Excel.Workbook. If the workbook has content in more than one cell I'm able to detect this, but if I have an empty "workbookA" and a "workbookB" with content in cell A1 I'm not able to seperate these.. Does anyone have a hot tip? (It's hard to find anything on excel-automation on google..)

    private bool IsWorkbookEmpty(Workbook excelBook)
    {
    try
    {
    if (excelBook.Sheets.Count <= 0)
    {
    return true;
    }
    else
    {
    foreach (Worksheet sheet in excelBook.Sheets)
    {
    Range excelRange = sheet.UsedRange;
    int test1 = excelRange.Columns.Count;
    int test2 = excelRange.Rows.Count;
    int test3 = excelRange.Count;

                if (test1 > 1 || test2 > 1 || test3 > 1)
                {
                    return false;
                }
                else //look for content..
                {
                    foreach(Range cell in excelRange)
                    {
                        object test5 = cell.FormulaR1C1;
                        object test6 = cell.get\_Value(Type.Missing);
                        //How do I check if cell has content?
                        //return true; if cell has content..
                    }
                }
            }
        }
    }
    catch (Exception)
    {
        return false;
    }
    return true;
    

    }

    C# question com testing tools tutorial

  • Performance tip on extracting BLOB from database?
    T Thomas ST

    Forgot to mention it, but yes, it's a big concern. I'm extracting almost 120GB of files stored in aprox. 400000 BLOBs. :) But thanks for suggestions :)

    C# question performance database sysadmin tutorial

  • Performance tip on extracting BLOB from database?
    T Thomas ST

    I don't have time to experiment ;) I'm going for a buffersize of 256*1024 (and I will let the compiler do the math ;)), and flushing every iter%16==0. The example I found online had buffersize=255 (equals 255 bytes right?), but it appears to be much faster with a bigger buffersize! It also seems like avoiding flush() is a good idea. Thanks for helping me out :)

    C# question performance database sysadmin tutorial

  • Performance tip on extracting BLOB from database?
    T Thomas ST

    So if default packet size for MSSQL 2008 is 4096 (Kbytes?), I could for example try to use 2048 Kbytes wich gives me: buffersize = 1024*2048=2097152? And if I want to flush every MB, something like this? :

    int startIndex = 0;
    int buffersize = 2097152; //(1024*2048=2097152)
    byte[] outbyte = new byte[buffersize];

    long retval = r.GetBytes(2, startIndex, outbyte, 0, buffersize);
    while (retval == buffersize)
    {
    bw.Write(outbyte);
    if(startIndex%1048576==0) //FLush every MB? (1024*1024=1048576)
    bw.Flush();
    startIndex += buffersize;
    retval = r.GetBytes(WriterTabell.Reader.GetOrdinal("nef_elfil"), startIndex, outbyte, 0, buffersize);
    }
    bw.Write(outbyte, 0, (int)retval);

    //flush, close, dispose

    With this code I usually get only 1 loop wich seems to be faster :) Is there any way I can find the optimal buffersize? Can .NET do the job for me (without using DataSet)?

    C# question performance database sysadmin tutorial

  • Performance tip on extracting BLOB from database?
    T Thomas ST

    But then you use DataTable, doesn't this load everything into memory first?

    C# question performance database sysadmin tutorial

  • Performance tip on extracting BLOB from database?
    T Thomas ST

    I am extracting 378000 BLOBS from a database. This is mostly pdf,doc, and docx, but also some big wav,tiff,mpg, ++. The code I'm currently using is a bit slow.. Does anyone have a tip on how to speed things up?

    using (r2d2 = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
    {
    if (!r2d2.HasRows)
    throw new Exception();

    DirectoryInfo dir = new DirectoryInfo(Path.Combine(\_arbeider.KonverteringsAlternativer.RootOutputDirectory, "DOKUMENT"));
    if (!dir.Exists)
        dir.Create();
    
    while (r2d2.Read()) //only one row...
    {
        string filnavn = Convert.ToString(r2d2\["filename"\]);
        string sizeString = Convert.ToString(r2d2\["size"\]);
        int size = 0;
        bool sizeOK = int.TryParse(sizeString, out size);
        bool filnavnOK = false;
    
        try
        {
            new System.IO.FileInfo(filnavn);
            filnavnOK = true;
        }
        catch (ArgumentException erna)
        {
            throw new Exception("file not valid");
        }
        catch (System.IO.PathTooLongException)
        {
            throw new Exception("path not valid");
        }
        catch (System.Exception errrr)
        {
            throw new Exception("filename not supported", errrr);
        }
    
        if (filnavnOK && sizeOK && size > 0)
        {
            FileStream fs = null;
            BinaryWriter bw = null;
    
            //checking for duplicates
            if (\_hashBrukteFilnavn.ContainsKey(filnavn))
                filnavn = Path.GetRandomFileName().Substring(0, 5) + filnavn; //duplicate
            
            \_hashBrukteFilnavn\[filnavn\] = true;
    
            try
            {
                fs = new FileStream(Path.Combine(dir.FullName, filnavn), FileMode.OpenOrCreate, FileAccess.Write);
                bw = new BinaryWriter(fs);
    
                completePath = Path.Combine(dir.Name, filnavn);
    
                int startIndex = 0;
                int buffersize = 3072; //what is best? default network-packet size for mssql2008 is 4096(?)
    
                byte\[\] outbyte = new byte\[buffersize\];
                long retval = r2d2.GetBytes(2, startIndex, outbyte, 0, buffersize);
    
                //This loop is a bit slow.. How can I speed it up?
                while (retval == buffersize) 
                {
                    bw.Write(outbyte);
                    bw.Flush();
                    startIndex += buffersize;
                    retval = r2d2.GetB
    
    C# question performance database sysadmin tutorial

  • Performance tip on multiple selects to retrieve alot of BLOBS?
    T Thomas ST

    I am retrieving a lot of data and want this to be as fast as possible. Let's say I have a database with two tables; tablePerson and tableFiles. A person has one file wich is stored in a BLOB. In my solution as it is now, I select * from person table, and while reading from this I select one row from the table with the blob.. This sums up to alot of one-row-queries towards the blob-table.. This blob-table has 678000 rows, and all these queries are taking a lot of time... So.. How can I improve performance on this? Any tips? This is something similar to my code:

    using(SqlCommand cmd = new SqlCommand("select * from tablePerson", _conn)
    {
    SqlDataReader r = cmd.exeCuteReader();

    while(r.read())
    {
    Person p = new Person();
    //read some data from columns..

    string documentID = Convert.ToString(r\["p\_docid"\]);
    p.LocationToDocument = ExtractDocument(documentID);
    

    }
    r.close();
    r.dispose();
    }

    ...

    private string ExtractDocument(string docid)
    {
    string filename = "";
    using (SqlCommand cmd = new SqlCommand("select d_docid, d_title, d_BLOB from tableDocument where d_docid=@paramDocID", _conn)
    {
    SqpParameter p = new SqlParameter("@paramDocID", System.Data.SqlDbType.Text);
    p.Value = docid;

      SqlDataReader r = cmd.exeCuteReader(System.Data.CommandBehavior.SequentialAccess);
    
      while(r.read()) //1 row..
      {
          //extract blob to a file, and set filename=that document..
      }
    

    }
    return filename;
    }

    Database question database performance code-review

  • FileNotFoundException on file that exists!
    T Thomas ST

    So that is what the @ is for :) Thank you for your answer, but I have to admit that I screwed up, and the file actually doesn't exist :doh: I am working with some testdata, and someone placed an error there (possibly on purpose?) :| That is a lot of hours wasted... :( the difference_: DL_JP_462153474_461535959_attest.JPG.pdf DL_JP_462143474_461535959_attest.JPG.pdf

    C# sysadmin help tutorial question

  • FileNotFoundException on file that exists!
    T Thomas ST

    Hi, I am running this code: string fullFilename = "\\\\server\\share\\DL_JP_462153474_461535959_attest.JPG.pdf"; byte[] bytes = File.ReadAllBytes(fullFilename); and get this exception: FileNotFoundException "Could not find file '\\\\server\\share\\DL_JP_462153474_461535959_attest.JPG.pdf'." The only problem is that the file does actually exist! Also, it works on files with shorter filenames in the same folder. For example: \\\\server\\share\\DL_JP_448856461_461530268_462153469.pdf Does anyone know what this is all about? :confused:

    C# sysadmin help tutorial question

  • How to dynamically add webservices in an application?
    T Thomas ST

    This is what I want to do: - I have made a WSDL (interface) which can be implemented by different web-services. Lets call this provideData.wsdl - I want to make a c# console application where I can dynamically add different services (different locations) which implements the same WSDL. Something like this: static void Main(string[] args) { AddDataProvider("http://serviceA/a.asmx"); AddDataProvider("https://serviceB/b.asmx"); //Do something with the data, using a shared interface.. } Normally when I consume a web-service in a C# project I just press "Add Service Reference...", but how can I do this dynamically with code? :^)

    C# question csharp wcf tutorial

  • Object "type not expected" when using serialization in web services
    T Thomas ST

    System.Runtime.Serialization is used for binary serialization. Since Webservices use Soap wich is xml, you should serialize objects to xml. Read this article on msdn about XML Serialization with XML Web Services. In your example, just import System.Xml.Serialization and add the annotation [System.Xml.Serialization.XmlTypeAttribute()]. And make public accessors to the members you want to be serialized.

    using System;
    using System.Runtime.Serialization;
    using Person;
    using System.Xml;
    using System.Xml.Serialization;

    namespace SchoolPackage
    {
    //This line is basically all you need for the class to be serializable
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.x.com/namespace/", TypeName = "Student")]
    public class Student
    {
    [System.Xml.Serialization.XmlElementAttribute(ElementName = "myCustomXmlElementName")]
    public string StrLastAlteredByUser
    {
    get { return strLastAlteredByUser; }
    set { strLastAlteredByUser = value; }
    }
    }
    }

    ps. personally I would let Student inherit Person :)

    C# help tutorial wcf sysadmin xml

  • Object "type not expected" when using serialization in web services
    T Thomas ST

    How do you annotate your custom objects to make them serializable? Something like this? :

    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://namespace/", TypeName = "person")]
    public class Person
    {
    private string _name;

    [System.Xml.Serialization.XmlElementAttribute(ElementName = "name")]
    public string Name { get { return _name; } }
    }

    And are you sure that you don't have any namespace-conflicts between your custom objects?

    C# help tutorial wcf sysadmin xml

  • help
    T Thomas ST

    I'm guessing you are doing something like:

    if(row["blah"]==null)

    and it should be

    if (row["blah"] == DBNull.Value)

    ?

    C# help

  • Parsing incoming DateTime in C# WebService myself?
    T Thomas ST

    I have a method in my Webservice:

    [WebMethod]
    public ReturnList GetList(string id, System.DateTime fromDate)

    If I enter a invalid date when testing the service, I get a custom html-page with the errormessage and a stacktrace. How can I get rid of this? I want to handle the parsing of the incoming date myself, and send back a ReturnList object with a custom errormessage.. But I don't want to use string instead of dateTime, since I want it to be specified as dateTime in the wsdl..

    C# question csharp html wcf testing
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups