Tuesday 17 August 2010

Jak pobrać listę raportów ?

Okazuje się to bardzo proste. Report server wykorzystuje do tego procedurę składowaną FindObjectsNonRecursive.


string cnxstr = "Data Source=moja_nazwa_serwera;Initial Catalog=ReportServer;Integrated Security=SSPI;"; //connection string
using (SqlConnection connection = new SqlConnection(cnxstr))
{
    connection.Open(); 
    SqlCommand command = new SqlCommand();
    command.Connection = connection; 
    command.CommandType = CommandType.StoredProcedure; 
    command.CommandText = "FindObjectsNonRecursive";
    command.Parameters.Add(new SqlParameter("@Path", "/nazwa_mojego_folderu"));
    command.Parameters.Add(new SqlParameter("@AuthType", 1));
    SqlDataReader reader = null
    try
    {
        reader = command.ExecuteReader(); 
        while (reader.Read())
        {
            string sciezka = reader["Path"].ToString(); 
            //teraz możesz np. wyświetlić ją na liście
        }
    }
    finally
    {  
        if (reader != null
            reader.Close(); 
    }
}

UrlEncode


public static string UrlEncode(string url)
{
    if (url == null)
        return null;
    StringBuilder bld = new StringBuilder(url.ToLower());
    bld.Replace("!", "%21");
    bld.Replace("*", "%2A");
    bld.Replace("'", "%27");
    bld.Replace("(", "%28");
    bld.Replace(")", "%29");
    bld.Replace(";", "%3B");
    bld.Replace(":", "%3A");
    bld.Replace("@", "%40");
    bld.Replace("&", "%26");
    bld.Replace("=", "%3D");
    bld.Replace("+", "%2B");
    bld.Replace("$", "%24");
    bld.Replace(",", "%2C");
    bld.Replace("/", "%2F");
    bld.Replace("?", "%3F");
    bld.Replace("#", "%23");
    bld.Replace("[", "%5B");
    bld.Replace("]", "%5D");
    return bld.ToString();
}


Tylko że można to zastąpić metodą HttpUtility.UrlEncode