Wiki.Page.Save C# (CSharp) Method

Save() public method

public Save ( ) : void
return void
        public void Save()
        {
            BeforeSave();

              using (SqlConnection conn = Db.OpenConnection()) {

            string sql = Exists() ? @"
            update pages
            set
             contents = @contents,
             author = @author,
             path = @path,
             urlpath = @urlpath
            where id=@id
            " : @"
            insert into pages
             ( contents, author, path, urlpath)
            values
             (@contents,@author,@path,@urlpath)
            ";
            using (SqlCommand cmd = new SqlCommand(sql, conn)) {
              cmd.Parameters.AddWithValue("@contents", contents);
              cmd.Parameters.AddWithValue("@author", author);
              cmd.Parameters.AddWithValue("@path", path);
              cmd.Parameters.AddWithValue("@urlpath", urlpath);
              cmd.Parameters.AddWithValue("@id", id);
              cmd.ExecuteNonQuery();
            }
              }
        }

Usage Example

Ejemplo n.º 1
0
    protected void bnSave_Click(object sender, EventArgs e)
    {
        // Get the slashes correct and trim it
        txtPath.Text = txtPath.Text.Replace('\\', '/').Trim();
        // Ensure they start with a slash
        if (!txtPath.Text.StartsWith("/")) txtPath.Text = "/" + txtPath.Text;

        // Ensure its a unique name
        String path = txtPath.Text;
        string urlpath = Wiki.Page.PathToUrlPath(path);
        int uniqCount=2;
        while (DbServices.PageExistsWithUrlpath(urlpath)) {
          path = txtPath.Text + " " + uniqCount.ToString();
          urlpath = Wiki.Page.PathToUrlPath(path);
          uniqCount++;
        }

        // Save it
        Wiki.Page page = new Wiki.Page();
        page.path = path;
        page.contents = txtRichEditor.Text.Trim();
        page.author = Auth.UserName;
        page.Save();
        Response.Redirect("./?" + page.urlpath);
    }
All Usage Examples Of Wiki.Page::Save